How to force two decimal places

I am having a brain freeze as I can’t figure this out and I am sure I’ve done it before.

How do I force a number to appear with 2 decimal places?

e.g.

2.1 would appear as 2.10
4 would appear as 4.00

1 Like

“:rounded to 2” or you could use “:formatted as Number” and specify 2 decimal places. Just be mindful that when you use “:formatted” then it changes from a number value to a text value.

1 Like

Awesome. I will do the former. Thanks Brian.

1 Like

It’s my pleasure. I had to get really good at enforcing rounding to 2 decimal places due to some WEIRD computer math stuff with looong trailing decimal places when all I was trying to do was calculate sales tax on financial transactions and such.

Hi again Brian.

It isn’t working. Here’s a screen grab of what I’ve got in and I am getting one of the numbers in a repeating group coming up as 4.1.

Weird, as that ‘rounded to 2’ should work.

All the numbers in the calculation as specified as decimals.

Any ideas Brian?

You mentioned a repeating group. Can you show us the text display in the repeating group? Or are you seeing the 4.1 displayed in this input?

Rounded to 2 wont work here as your original numbers already have less than 2 decimal places (so are already rounded to 2 decimal places)

Using rounded to 2 will round a number to 2 decimal places but by default bubble wont show unnecessary decimal places - so 4.2768 will round to 4.28 and show as 4.28, but 4.1 will round to 4.1 and show as 4.1.

If you want to display a number with 2 decimal places (even if they are 0) you need to use ‘formatted as number’, to 2 decimal places.

Thanks for your input Adam. I did try that, but one of the number displayed as 56.4.

Here’s what I have in:

What am I do wrong do you think?

I see in your screenshot that you’re applying that formatting to the initial content in the input which is set to be a decimal.

The issue is (as @BrianHenderson mentioned above) that when you format a number it becomes a text. Your input field is set to take an actual number input ( the number 4.100000000000 is the same as the number 4.1 or 00000000004.1 - these zeros are meaningless in a number) so you can’t format that as a text.

So if you want to format a number to display it to a certain number of decimal places you have to do that as a text (which you can’t do in an input field that’s set to be a number).

So the input (as a number) will only ever display as a number (i.e. the actual number as it exists).

The only workaround, if you want to display the input number to 2 decimal places as it’s entered is to have a separate text element next to the input which displays the input number, formatted (as a text) to 2 decimal places.

Unless, that is, you’re trying to display monetary values, in which case you can select the ‘currency’ option in the content format, and select the ‘always show decimals’ option. Then it will display the value in the input showing 2 decimal places at all times (but will also show the selected currency symbol).

2 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.