There is a special algorithm on how we handle tax rounding algorithm in our system.


Example: 


Line
Qty
Unit Price
Tax
Tax (Before Round)
Tax (After Round)
1
1
13.11
6%
0.7866
0.79
2
1
13.11
6%
0.7866
0.79
3
1
13.11
6%
0.7866
0.79
4
1
0.00
6%
0.0000
0.00
Total

39.33


2.37


If you calculate the tax line by line and perform rounding to 2 decimals, the total tax of the above transaction will be 2.37. However, if you use 39.33 x 6% = 2.3598, after rounding will be 2.36 which has a 1 cent difference compare to 2.37.


In order to solve such issues, the easiest way is to apply this 1 cent to the last row of the transaction, then it will become below example:


Line
Qty
Unit Price
Tax
Tax (Before Round)
Tax (After Round)
1
1
13.11
6%
0.7866
0.79
2
1
13.11
6%
0.7866
0.79
3
1
13.11
6%
0.7866
0.79
4
1
0.00
6%
0.0000
-0.01
Total

39.33


2.36


However, this will cause some confusions as the last line has no Unit Price but why is there tax amount? Therefore, we had derived this into a rounding algorithm called Adaptive Rounding Algorithm. This algorithm works from top to bottom.


Line
Qty
Unit Price
Tax
Tax (Before Round)
Previous Before Round Total
Previous After Round Total
Tax (After Round)
1
1
13.11
6%
0.7866
0.7866
0.79
0.79
2
1
13.11
6%
0.7866
1.5732
1.57
0.78
3
1
13.11
6%
0.7866
2.3598
2.36
0.79
4
1
0.00
6%
0.0000
2.3598
2.36
0.00
Total

39.33




2.36


This algorithm applies the formula:

Round (Sum of Tax Before Round from Line 1 to Line N) - Sum (Tax from Line 1 to Line N-1)


The tax of Line 1 is

= Round (0.7866)

= 0.79


The tax of Line 2 is 

= Round (0.7866 + 0.7866) - (Line 1 Tax)

= Round (1.5732) - 0.79

= 1.57 - 0.79

= 0.78


The tax of Line 3 is 

= Round (0.7866 + 0.7866 + 0.7866) - (Line 1 Tax + Line 2 Tax)

= Round (2.3598) - (0.79 + 0.78)

= 2.36 - 1.57

= 0.79


The tax of Line 4 is

= Round (0.7866 + 0.7866 + 0.7866 + 0.0000) - (Line 1 Tax + Line 2 Tax + Line 3 Tax)

= Round (2.3598) - (0.79 + 0.78 + 0.79)

= 2.36 - 2.36

= 0.00


By using this method, Line 4 will not have any tax amount because the Unit Price is 0.00. However, it may make the intermediate lines has tax values such as Line 2 having 1 cents different with other lines that have similar Unit Price.


But because in the end, people mostly check their tax amount of the transactions as a whole instead of individual item, so we have applied this algorithm in our calculation. In other words, as long as the total tax is correct, then you will not have to worry much about the individual tax amount at each lines.