## Incorrect tax rounding and application in Prestashop 1.6.1 and 1.7

Prestashop 1.6.1 and above, and Prestashop 1.7 and above, present a tax application problem when rounding system is set Round on each item and a rounding problem when set to Round on each line or Round on the total.

Prestashop cart calculates at first the total price tax excluded and tax included, and then applies a subtraction to get the total tax amount. This procedure, in our opinion, leads to a rounding problem. Let’s see why.

Round on each item calculation

This is a real example:

1. A product gross price (tax included, 22% tax rate) is 2,95 : Prestashop calculates the net price (tax excluded) being 2,418033
2. Moreover our product is on sale at 32% discount, taking the net price to 1,644262 .
3. If the rounding is set to Round each item, and we add to cart 2 items well get the following values:
- unit net price 1,64
- total net price 3,28
- tax 0,74
- total gross price 4,02

Prestashop gets these values by applying taxes to a net price of 1,644262, in doing so getting a gross price of 2,005999, rounded to 2,01

1. Lets perform a simple check: If to a net price of 3,28 we apply a tax rate of 22%, the result is 4,0016 rounded to 4,00. This value differs from the 4.02 as calculated in the Prestashop cart.

Round on each line or Round on the total calculation

If the rounding is set instead to Round on each line or Round on the total, there is a problem whit tax application that is performed before quantity sum up.

By using the same product of the above example, and placing into the cart 1 item, we get:
- unit net price 1,64
- total net price 1,64
- taxes 0,37
- total gross price 2,01

By reviewing Prestashop carts process, the total gross price (tax included) gets calculated by applying taxes on a net price of 1,644262 that equals to 2,005999, rounded to 2,01

By performing the same check done before, if we apply taxes to the total net rounded price (the taxable income for each order line), we get 2,0008 rounded to 2,00.

To fix these issues, we have modified the Cart.php class, applying calculation on net prices at first and applying taxes only at the end of rounding.

If you agree with our vision of these issues, you can find a