there is a general relationship between the prices, the quantity, discount, tax and their precisions.
Assume:
x is the price
y is the percentage
s is the rounded sub-total
2 Directions
A) incl. Tax => excl. Tax => incl. Tax
B) excl. => incl. => excl.
The important issue is the rounded subtotal
I am calculating with the max. Error. 2 fractional digits means 5*10^-3
A) x*10^2/(y+10^2) // s*(y+10^2)/10^2
B) x*(y+10^2)/10^2 // s*10^2/(10^2+y)
A)
Subtotal precision 2 fractional digits:
5*10^-3*(y+10^2)/10^2 => (y+10^2)/10^2<1 => no y
3 fractional digits:
5*10^-4*(y+10^2)/10^2 => (y+10^2)/10^2<10 => y<900
4 fractional digits:
5*10^-5*(y+10^2)/10^2 => (y+10^2)/10^2<10^2 => y<90900
(must be a very bad country)
......
B)
Subtotal precision 2 fractional digits:
(5*10^-3)*10^2/(10^2+y) => 10^2/(10^2+y)<1 => every y
If you want to calculate with discounts or taxes and want to recalculate the price,
the next explanation can be interesting for you.
Please be aware since I don't know any case in the front-end, it is possible there is
an intern calculation.
A) Total => Tax/Discount =>Total
B) Tax/Discount => Total => Tax/Discount
A) x*y/10^2 // s*10^2/y
B) x*10^2/y // s*y/10^2
A) Subtotal precision 2 fractional digits:
(5*10^-3)*10^2/y => 10^2/y < 1 => y>10^2
Subtotal precision 3 fractional digits:
(5*10^-4)*10^2/y => 10^2/y < 10 => y>10
Subtotal precision 4 fractional digits:
... 10^2/y < 10^2 => y>1
With a precision of 2 digits, you must have a rate with NO FRACTIONAL DIGITS.
Example:
Total: 15,15 tax-rate: 0,3% => tax 0,04545 => rounded 0,0455
tax: 0,0455 => total: 15,17
B) Subtotal precision 2 fractional digits:
(5*10^-3)*y/10^2 => y/10^2 < 1 => y < 10^2
if a is the precision, than must be y less than a+2.
Please note if you handle quantities. The error will be multiplicated.
So if you have a max of 10^5, you have to have a precision of 7.
This is only worrying, if you are calculating with offset!
ADDITION (9.10.2013 Magento Version 1.7.0.2)
Brutto <=> Netto and Taxes // America <=> old Europe
Sets are integers (Cents)
and the mapping
f(x) = round(a*x) a>1
is not bijective.
In my words:
Not for every price incl. exists a price excl.
or
There are sometimes 2 prices incl. for one price excl.
or
You can get 2 different results depending how you calculate
Real-world-example from Germany:
You try to enter a price incl. taxes: 19,95
You get 16,76 (2 digits) as your prices excl. the taxes (19%).
If you calculate the 19% taxes you get (16,76*0.19) 3,18.
(Be aware: 19.95 * 019/1.19 ~ 3.19)
So there is 1 Cent difference.
16,76 => 19.94
16.77 => 19.96
There is no price 19,95 in america - land of netto.
So calculate with original prices as far as possible. For including prices use entered price and the taxes (broken number).
PayPal has this fraud check - now i'm not sure - but PayPal just adds the number magento gives it. see http://fabiankrueger.de/blog/magento-und-paypayl-rundungsfehler/
If this is not true and PayPal recalculate Tax or Total, this problem is not solvable, else the prices - wrong or right - are shown before in Magento. Solve it there.
For me it seems to work.