1.10
has two decimal places, while 1.1020
has four. Precision significantly impacts calculations. Consider removing 21% from a price of 10 with two decimal places, then re-adding it:
10.00
÷ 1.21
= 8.26
8.26
× 1.21
= 9.99
(one cent loss)10.0000
÷ 1.21
= 8.2645
8.2645
× 1.21
= 10.0000
(no loss)8.2556
becomes 8.25
, but this can cause calculation errors. A better approach is rounding to the nearest number. If the excess digits are 0.50 or higher, round up; otherwise, round down. For example:
8.2551
becomes 8.26
.8.2550
becomes 8.26
.8.2549
becomes 8.25
.precise
- the default, with two additional decimal places, and,currency
- use the precision of the currency.122.61
, not 122.62
as would be expected by summing the line totals – we can see why if we add a 0
to each item’s price:
EL
) require the rounding method and it will be chosen automatically. To apply the currency rounding method, update the document’s tax object with: