1 2 Previous Next 17 Replies Latest reply on Oct 18, 2015 8:10 AM by beverly

    decimal to fraction

    AndrewJudd

      HI all, I'm looking for a script to change three number fields from decimals to fractions.

       

      Ideally this could be a checkbox that runs a script on modify so a user can have either decimal or fraction in the same fields - if possible? These are 3 number fields where inches are entered.

       

      I also have 3 number fields below them that are calculation fields to cm - so I need to keep these from being affected. My cm fields have this calculation -

       

      Round (H*2.54 ; 1)

       

      Any ideas?

        • 1. Re: decimal to fraction
          beverly

          I think you mean "reduced fractions" as 50/100 = 1/2.

          I did a search for "filemaker reduced fractions" and got several suggested links (articles, plugins and custom functions), such as;

           

          FileMaker Custom Function:FractionReduce( fraction )

           

          FileMaker Custom Function:FractionMath( fraction1 ; Fraction2 ; Operator )

           

          Decimal to Fractions on Filemaker Pro 12.0V2 . Using FileMaker Pro . Forum . FileMaker Forums

           

          BTW, the link to a plug-in appears to only by support help documentation and no link to a plug-in.

           

          beverly

          • 2. Re: decimal to fraction
            AndrewJudd

            Thanks Beverly, I simply mean if a user enters 50.5 into a number field they have the option to display the data as 50 1/2, and so forth.

             

            I don't see the decimal points being crazy difficult, most likely .25, .5, .75 for now.

             

            If there is a way to go more complex then great.

            • 3. Re: decimal to fraction
              AndrewJudd

              This one is it -

               

              http://www.briandunning.com/cf/55

               

              But how do I apply the custom function, do i need to set all of those at least 200 or so lines with my "number" field?

              • 4. Re: decimal to fraction
                beverly

                correct. (.5) = 5/10, but REDUCED is 1/2

                 

                See the custom functions and the links to the articles.

                 

                I would not have the SAME field display the decimal OR fraction. The fraction is TEXT and decimal is NUMBER. I would have a 'display field' as TEXT that would allow a "toggle between" the view of the NUMBER field. Toggle between decimal or reduced fraction view of the number.

                 

                Use a custom function to set the display field to decimal or fraction. (turn the field into a button to perform the swap)

                 

                if ( PatternCount(mydisplay; ".") // we have a decimal!

                ; Set Field .... // use custom function to convert mynumber to fraction

                ; Set Field ... just use the original number

                )

                 

                Of course, there may be WHOLE NUMBERS (no fraction/decimal), so the above may need to be a "Case()" testing for no "."  and no "/".

                 

                Check out the Custom Functions to see if these work for you.

                 

                HTH,

                beverly

                • 5. Re: decimal to fraction
                  DamianKelly

                  mod ( mydisplay; 1 ) > 0 might be a better test for a decimal?

                  • 6. Re: decimal to fraction
                    Extensitech

                    While I haven't ever been asked for fractions, I've seen a similar pattern where entering units of measure, such as inches, feet, mm, cm, etc.

                     

                    What I ended up doing was leaving the "as entered" as it was, but then establishing a calc to translate any of those into a common measure (we chose inches just because it was the most common in that case), and then adding a tooltip with a translation into all the available units of measure.

                     

                    More challenging was searching. We had to do some scripting in find mode so that if the user entered, for instance, 2 and "ft", we set that into globals, which wouldn't affect the find but would let them see what they put in, and then set the standard "in" field to 24 so that the find would result with 2 ft items, 24 in items, etc. Just to make things more fun (seriously, to make it less "clunky") we allowed for >, <, >=, ranges (...) and so forth.

                     

                    In the end, this proved really useful for that particular solution. The items in the db sometimes had a measure that was "just what people call it", or a measure that was used by the vendor or customer, so entering measurements in a variety of different ways actually made the entry and working with the items easier (it wasn't just laziness), but we were able to compare items "apples to apples" in the many places we needed to.

                     

                    Again, not fractions, but the pattern seems similar. Let the user enter the values in the way that normally "makes sense" but let them find either way, and let them see alternate ways when they need to.

                     

                    Chris Cain

                    Extensitech

                    • 7. Re: decimal to fraction
                      beverly

                      Yes, if tested against the original NUMBER field, not the calculated (by script) TEXT field.

                       

                      -- sent from myPhone --

                      Beverly Voth

                      --

                      • 8. Re: decimal to fraction
                        siplus

                        You need Filemaker Pro Advanced to

                         

                        "copy & paste into FileMaker Advanced's Edit Custom Function window."

                        • 9. Re: decimal to fraction
                          beverly

                          yes to add these to custom functions to your database, you do need Advanaced. once added they can be called by non-avanced fmp. however, they are calculations. IF they call other values or are recursive (calling themselves), they may still be used as basis to SCRIPT the process. The functions may give clues to what others have done to make decimals into fractions.

                           

                          beverly

                          • 10. Re: decimal to fraction
                            AndrewJudd

                            Thanks all, still not relly sure what I'm supposed to put in here..

                             

                            Screen Shot 2015-10-18 at 12.47.07.png

                            • 11. Re: decimal to fraction
                              AndrewJudd

                              and in actual fact, this below would be more useful.. as the user puts in the measurments in fractions, i need to chang to decimal and then have this figure calculated to cm's. which i have as "Round (H*2.54 ; 1)".

                               

                              How do I add this to custom functions?

                               

                              Thank you..

                               

                               

                               

                              /*

                              Convert valid fraction to decimal equivalent

                              Require Functions

                                  FractionType

                                      FractionNumerator

                                      FractionDenominator

                              © Brett Buchmiller 10-2010

                              */

                               

                              If( FractionType ( Fraction1 ) ≠ "Invalid" ;

                                  FractionNumerator ( Fraction1 ) / FractionDenominator ( Fraction1 )

                              )

                              • 13. Re: decimal to fraction
                                erolst

                                Read the description from the original CF:


                                /*

                                Convert valid fraction to decimal equivalent

                                Require Functions

                                    FractionType

                                        FractionNumerator

                                        FractionDenominator

                                © Brett Buchmiller 10-2010

                                */

                                 

                                FractionType etc. are not parameters/arguments, they are other, “require” [sic] CFs that you need to define beforehand before you can reference them in this CF. (The only argument seems to be fraction1.) You will probably find them wherever you found FractionToDecimal().

                                • 14. Re: decimal to fraction
                                  AndrewJudd

                                  got it, all works well.... fractions turn to decimals fine. However if the number is a whole number my new field (WDecimal) remains empty. is there a way to tell it when a whole number just take the number entered into field "W".

                                   

                                  thanks!

                                   

                                   

                                   

                                  Screen Shot 2015-10-18 at 13.31.08.png

                                  1 2 Previous Next