Jump to content

function for 2 decimal places format


This topic is 2332 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have a calculated field that makes up part of the body of an email. It looks like this:

"Total new charges:" & $InvoiceTotal

When this prints, if the invoicetotal is 79.90, it prints 79.9. If the invoice total is 79.00, it prints 79. How can I get it to always print with 2 decimal places?

Link to comment
Share on other sites

I use a calculation by Comment which allows the most flexibility and control possible. You can specify the precision, currency, separator etc:

[color:blue]Let ( [

// USER DEFINED:

input = numberfield ;

precision = 2 ;

currency = "$" ;

separator = "," ;

decPoint = "." ;

// DO NOT MODIFY FROM THIS POINT ON

inputRound = Round ( input ; precision ) ;

Amt = Abs (inputRound ) ;

Dollars = Int ( Amt )

] ;

// PREFIX

Case ( inputRound < 0 ; "-" )

& currency

&

// BILLIONS

Choose ( Dollars < 10 ^ 9 ; Right ( Div ( Dollars ; 10 ^ 9 ) ; 3 ) & separator )

&

// MILLIONS

Choose ( Dollars < 10 ^ 6 ; Right ( Div ( Dollars ; 10 ^ 6 ) ; 3 ) & separator )

&

// THOUSANDS

Choose ( Dollars < 10 ^ 3 ; Right ( Div ( Dollars ; 10 ^ 3 ) ; 3 ) & separator )

&

// UNITS

Right ( Dollars ; 3 )

&

// FRACTION

Choose ( precision < 1 ; decPoint

&

Right ( 10 ^ precision & Amt * ( 10 ^ precision ) ; precision ) )

)

You will not use it only once but many times when this type of need arises. :wink2:

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...
  • 7 years later...
  • 7 months later...

LaRetta

Thank you so much for this. I have been hunting for an answer to correctly entering the result of a calculation for an Invoice total into an eMail for SO long and I stumbled across your calculation which just works.

You are a star!

Link to comment
Share on other sites

This topic is 2332 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.