I am working on a pricing page for my product.

To calculate cost per user per month, I divide monthly cost by number of users in the plan.

When the monthly cost is 19.99 for 5 users, the division leads 3.9979999. But when I tried to round that number to 2, it shows as 4 instead of 3.99, and when I use formatted as and specify two digits after the decimal point, it also comes out as 4.00 instead of 3.99.

Is that a bug with Bubble’s math engine? or am I doing something basically wrong?

Very interesting about the :formatted as… You’re correct that it also rounds the number…

Just did a look through and I couldn’t find an immediate workaround for you.

It does seem like a bug.

Make the calculation.

Round the 3.997… and if will be 4. Because the 7 will add 1 to 9… that will add 1 to 9… and give 4. I don’t think this is a bug

@Jici is correct here… this is not a bug…

3.9979999999999998 rounded to 2 decimal places is indeed 4

If that’s the case, what is the best way to round 3.9979999999 to 3.99?

P.S. I would at least expect 3.997999999 rounded to 3 decimal points (3.998) formatted as number with 2 decimal places will lead 3.99, but it’s also producing 4

If you specifically only want to have numbers, such as prices, ending in ‘.99’ you can just use `ceiling-0.01`

to round the number up to the nearest whole number then deduct 1 cent (0.01)

P.S. 3.997999999 rounded to 3 decimal places *is* 3.998 and I’ve just tested for myself in Bubble and it works as expected…

So if you’re seeing 4 when using rounded to 3 then that does sound like a bug, as it should be 3.998, and is for me.

If you’re using ‘Formatted As’ to do additional rounding to 2 decimal places then I would still expect to get 4 (as 3.998 rounded to 2 decimal places is 4)

Thank you.

This works if all prices are X.99

But if any other price is different, like X.89, this still shows X.99, which is not scalable in my case.

Edit: I think this is more of Formatted As… bug, as it should not round numbers, but rather convert them to text and truncate them properly. In other words, 3.997999 formatted as text with 2 decimal places should be 3.99 not 4.00

Yes I’m in agreement here with you @akhella . **Formatted as should not round automatically.** Rounding should only be done if you specifically tell Bubble to round the number.

That’s mathematically impossible *if* you’re rounding by the smallest US denomination - i.e. cents. You could certainly *truncate* it to 3.99, but that would yield an inaccurate result. If you multiply 3.99 x 5, you get 19.95 and that’s 4 cents off; whereas 4.00 x 5 is 20.00, which is only 1 penny off.

As others have said, this is not a bug; but you could certainly reconsider your pricing strategy and/or wording.

-Steve

Hi @akhella,

You should multiply your number by 100, then :floor, then divide by 100.

3.9979 x 100 = 399.79 => :floor => 399 => /100 => 3.99

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