4 Replies Latest reply on Jun 20, 2013 3:24 AM by sportyguy209

    Forced Decimal Place Formula Help

    sportyguy209

      Title

      Forced Decimal Place Formula Help

      Post

      I'm not a programmer, but usually manage to get FileMaker to do what I need it to do. However, I'm stumped on this one.

            
           I am trying to create a field that will always provide two decimal places.      
                 
                15 should show up as 15.00
                15.1 should show up as 15.10
                15.01 should show up as 15.01
                 
                This is the formula I have been using:
                 
                Let ( [ d = Round ( Self ; 2 ) ; i = Int ( d ) ; f = ( d - i ) * 100 ] ; i & "." & Left ( f & "0" ; 2 ) )
                 
                However, when I enter 15.01, the result is 15.10
                 
                Can someone tell me a formula that will work?
                 
                TIA

            

        • 1. Re: Forced Decimal Place Formula Help
          philmodjunk

               Why not just use data formatting on the inspector's data tab to format the data to have two decimal places?

               There are cases where such a calculation is necessary, but I wouldn't use a calculation if formatting the field achieves an acceptable result as it is much simpler.

               Let ( [ d = Round ( Self ; 2 ) ; i = Int ( d ) ; f = ( d - i ) * 100 ] ; i & "." & Right ( "0" & f ; 2 ) )

          • 2. Re: Forced Decimal Place Formula Help
            sportyguy209

                 Thank you, that worked!

                 I don't remember why, but I was not able to get the inspector's data tab to work. The numbers showed up correctly in FileMaker, but when I exported the data, if there were 0's at the end of the number (15.00 turned into 15), they were dropped or something like that.

            • 3. Re: Forced Decimal Place Formula Help
              philmodjunk

                   Yes, that is one reason for using the calculation. The data format option in the inspector is for display purposes only, it does not change the data actually present in the field--which is what is then exported.

                   Please note that rounding values like this should be done with caution. If the value is used in subsequent calculations that reference the rounded instead of the unrounded value, you could introduce error into your calculated result. In such cases, you may need to have a calculation field with this expression to use for exporting the value while you use the original value for such calculations.

              • 4. Re: Forced Decimal Place Formula Help
                sportyguy209

                     In this case, I am just interested in being able to export the field with the correct number of decimal places.

                     But, I understand your warning about relying on the field for subsequent calculations.

                     Thanks again!