Rounding issue with decimals

Hello,

I´ve found that whenever we´ve a calculation of an invoice total that is something like 1.208,665 € and you do the “format as currency and 2 decimals” Bubble rounds the 665 to 67 so you get 1.208,67 € and it should be 1.208,66 €.

Is there any way to fix this? Since it´s getting a lot of issues when moving the invoices to our accounting program because the accounting app checks the calculation and it says that it should be 1.208,66 € instead of ,66 so it won´t let us import the invoices.

Thanks a lot everyone.

Bests.

Subtract 0.5 then round.

Sorry Nigel, what do you mean?

We have to keep in mind that it´s one case so we cannot do for every calculation just when that happens.

Sorry, I mean 0.005.

So when you store the invoice total, every time you subtract 0.05 and round up. That is the way to round to the nearest 2 dp.

But what happens if it´s 1.208,6656 for example?

Also I´ve tried to see the subtract in the workflow calculation but there is nothing there.

Thanks a lot.

I was getting confused by the , and . being the other way round to anglo-saxons :slight_smile:

1208.6656 - 0.005 = 1208.6606 so round it up … 1208.67.
1208.6646 - 0.005 = 1208.6596 so round it up … 1208.66.

At least that is what I think you are after.

But there is a problem there, what if the number is just 10 €, if I subtract 0,005 then it will be 9,995 €

Then we have a problem, hehe

What do you think?

That will round up to 10.

Uf I don´t know if this solution is a good idea since we´re working with numbers and I need to check if there will be an issue because it could be any number.

Don´t you think?

Just tried that and it rounds to 9.99

You are right, it does.

So you want to round down to the nearest dp 2 each time ?

(I had thought Bubble always rounded up).

Try @NigelG’s method, but specifically round it to two digits, instead of relying on the formatting:
number - 0.005 :rounded to 2

And maybe raise a bug on the formatting not being consistent?

It is a bit weird, and I was fairly certain it rounded .5 up, but it appears to round it down.

So - 0.05 then +0.0001 should do it.

But … I tend to agree that it isn’t particularly robust.

Thanks a lot but I think I´ve to digg in a little bit since it´s getting complicated to find a pattern.

Maybe this helps… to output the number, there are two stages:

  • Change the value to stop after two digits. Alternatives:

  • subtract 0.005, then :round 2

  • multiply by 100, then :floor, then divide by 100
    133 stays as 133
    133.999 becomes 133.99

  • Show the changed value with two digits. Use the :formatted as 1.234,56
    133 shows as 133,00
    133.99 shows as 133.99

Both stages can be done in the same expression.

I haven’t looked at this, but are they applying Bankers rounding (Round half to Even)?

I think the standard JS Round() function goes to the nearest integer with .5 always going UP.

Here are the different rounding methods… https://en.wikipedia.org/wiki/Rounding

Regarding Bankers Rounding, where:
2.5 is rounded to 2
3.5 is rounded to 4
4.5 is rounded to 4

How do you achieve this type of rounding in bubble?

For instance-
Item Subtotal is $79.00
7.5% Sales Tax is $5.925

We need this to end up as .92

If it were .935, we’d need it to round up to .94

I really appreciate any help or pointers. Thanks!

This is actually still a relevant topic. Is there absolutely no reliable way of cutting any long number down without rounding? E.g. 0,136666667 → 0,13

:rounded to will round to 0,14
:formatted as will also round to 0,14

Thank you!

@hi_bubble [number] * 100:floor / 100