SS
Reported
I just tested this on the demo to confirm it's not unique to my system.
See the attached images.
One the one hand, it is just a display bug or computation error on the invoice entry form.
However, it confuses everyone and as we have a lot of $2.00 sales, I'm getting a lot of errors.
Clerks get busy, look at Grand Total, and put in a payment of $2.19, and then of course the sale is only partially paid and someone has to correct the error (we don't allow clerks to do that.)
See the attached images.
One the one hand, it is just a display bug or computation error on the invoice entry form.
However, it confuses everyone and as we have a lot of $2.00 sales, I'm getting a lot of errors.
Clerks get busy, look at Grand Total, and put in a payment of $2.19, and then of course the sale is only partially paid and someone has to correct the error (we don't allow clerks to do that.)
- SSAnsweredThe following fixes the display rounding errors in themes/default/assets/js/custom.js around line 286.
```
// fix rounding errors for displayed amounts in invoice add/edit
total = Math.round((total + Number.EPSILON)*100)/100;
order_discount = Math.round((order_discount + Number.EPSILON)*100)/100;
order_tax = Math.round((order_tax + Number.EPSILON)*100)/100;
shipping = Math.round((shipping + Number.EPSILON)*100)/100;
grand_total = (total - order_discount) + order_tax + shipping;
$('#order_discount_total').text(formatMoney(order_discount));
$('#order_tax_total').text(formatMoney(order_tax));
$('#grand_total').text(formatMoney(grand_total));
```
I will still be watching the sales and payment fields in the database -- at least for a while -- until I'm sure this isn't slipping through elsewhere. - SSAnsweredFloating point is the worst!
I miss my old system from 30-40 years ago. It had a Binary Coded Decimal data type. Very useful for dealing with financial and scientific data.
Absent that, I think it is better to just use integers and "count" in the smallest currency unit (one cent in the US). It requires a little manipulation on input (move the decimal) and display (move the decimal the other direction), but it's not so bad.
Too bad there is so much pre-existing floating code in compilers, libraries, frameworks, etc. Impractical to change unless you're coding from scratch.
https://husobee.github.io/money/float/2016/09/23/never-use-floats-for-currency.html - MSAnsweredHello,
Yes, might be js rounding. I will check it tomorrow.
Thank you - MSAnsweredHello,
I have checked. `accounting.js` is causing the issue. It should round `2.195` to `2.20` but it's rounding to `2.19`
I will update to `number_format` partially in future updates.
Thank you - Login to Reply