1 Reply Latest reply on Sep 17, 2013 9:08 AM by davidanders

    Rounding

    germain

      Title

      Rounding

      Post

           Using a formula like this one

      Int(Number) + Choose(Int(Mod(Number, 1) /.25), 0, .25, .50,.75) 

      How would I change it to round to the NEXT 1/8.

           example: I need to round

           23 1/16 to 23 1/8

           23 11/32 to 23 3/8 ....... and so on!

      Thanks

        • 1. Re: Rounding
          davidanders

               Googleing did not find much

               FROM  Newb trying to create fractions from decimals...

                      
          •                posted February 27, 2009 by comment 
          •      
                         I'd suggest you make this in two steps, otherwise your formula will be utterly unreadable in version 6. The first step is to divide X by Y and round the result to nearest 1/32 (result is Number):

          Round ( X / Y * 32, 0 ) / 32
                         Note that here we have no protection against Y being 0 or empty, which will result in an error.

                         Let's call the previous result n and move to the second and final step* (result is Text) =

          Case ( Int ( n ) ,  Int ( n ) &  " " )
                         &
                         Case (
                         Mod ( n, 1 ),
                         Mod ( n, 1 ) * 2^( Length (  Mod ( n, 1 ) ) - 1 )
                         &  "/"  &
                         2^( Length (  Mod ( n, 1 ) ) - 1 )
                         )


                         ---
                         (*) adapted from http://www.onegasoft.com/tools/commonfractions/index.shtml

                

               Search for "fraction"  http://www.briandunning.com/filemaker-custom-functions/results.php

          Fractions to Decimals    By:    John Mark Osborne
          http://www.databasepros.com
          Number to Fraction    By:    John Mark Osborne
          http://www.fmfiles.com/tnt1.html

          http://dwaynewright.squarespace.com/filemaker-calculations/2008/7/15/filemaker-rounding-to-the-half.html