When using the Money formatter in a formula how do I force the presentation of decimals?

I use a lot of formulas the calculate a price in USD with the money formatter {=price; format=$,}

I like this formatter for money because it will only show the decimal if the result is not a whole number. The one problem with this formatter is that if there is a decimal that is divisible by 10 (1.1) for example it will represent the price as $1.1 rather than presenting it as $1.10. If it's a decimal that is not divisible by 10 (1.22) then it generates $1.22 which looks correct. I feel like a formatter that is dealing with USD should conform to the presentation standards of that currency but I digress. Is there a way to fix this issue in a formula?

Price:{formtext: name=price} <--Enter a number with just 1 decimal after the whole number and see the non ideal formatting below. For example enter 1.1, then try 1.11 and see the difference.

Formatted price:
{=price; format=$,}

1 Like

Try this:

Price:{formtext: name=price;default=10} <--Enter a number with just 1 decimal after the whole number and see the non ideal formatting below. For example enter 1.1, then try 1.11 and see the difference.

Formatted price:
{=price; format=$,.2f}

Thanks but that always shows the decimals though. I want the formatted number to show no decimals (or decimal point) if the number is whole. Any ideas?

@Joe_P We can do that with an {if} command that looks for whether or not a decimal point is in the price field input.

Price:{formtext: name=price; default=10}

Formatted price:
{if: contains(price, ".")}{=price; format=$,.2f}{else}{=price; format=$,}{endif}

1 Like

Hurray! Thanks man. That's great.

While I have you, I have one more similar problem to solve. I have a formula where I'd like to achieve the same formatting trick where it drops the decimal if it's not needed. Can you point me in the right direction for how to solve? I'm guessing there's a way to put if statements in a formula but I'm having a helluva time figuring it out...Your assistance is very appreciated.

Price:{formtext: name=price}
Commission: {formtext: name=commissionamount; default=0}
Amenity Fee: {formtext: name=amenityfee; default=0}

Result: {=price+price+amenityfee+commissionamount+25; format=$,.2f}

@Joe_P in this case, you'd want to save your calculation as its own variable first, and then use the if statement to evaluate that variable the same way that we did in the previous one, outputting that variable with different formatting depending on the result of the if.

Price:{formtext: name=price}
Commission: {formtext: name=commissionamount; default=0}
Amenity Fee: {formtext: name=amenityfee; default=0}

Result: {result=price+price+amenityfee+commissionamount+25}{if: contains(result, ".")}{=result; format=$,.2f}{else}{=result; format=$,}{endif}

This might be on purpose but FYI in your result calculation you're adding the price in twice.

1 Like

Thanks, that works well. For some reason I didn't think to make a variable. Thanks for noticing that double up on the price value. In the specific use case it was intentional but if it wasn't you'd have saved me.