Hi, I have (different) rounding problem
I have an invoice, with invoice lines.
one invoice line has:
quantity * (saleprice - discount %) = total
quantity = 12
saleprice = 8.95
discount = 10 (%)
to calculate the price minus discount the calculation is as follows:
var a = 8.95 - (8.95 * (0.01 * 10)) //==8.055
var b = Math.round(a * 100) / 100 //== 8.06
12 * 8.06 = 96.72
This is correct, and there is further no problem.
But sometimes we duplicate the invoice to create a Credit Invoice.
We duplicate than the invoice-line and set the 8.95 to -8.95
but now the rounding goes wrong (in our case)
var a = -8,95 - (-8.95 * (0.01 * 10)) //== -8.055
var b = Math.round(a * 100) / 100 //== -08.05
12 * -8.05 = -96.60
As you can see in this example, the difference is 0.12.
I was wondering if someone came across this problem, and how to solve this.
I have some ideas, like: setting the quantity to -12, instead of the price.
Than the calculation goes oke, but I can't prevent users, by setting manually the price to a negative number..