Different results from adding tax to each item's price versus adding it to the total

207 Views Asked by At

The math problem I encountered which is a bit of an anomaly is this :

Suppose you are producing an invoice for a customer, and all items for that invoice are stored in a list (without taxes pre-calculated):

Hamburger - 5.24
Pizza Slice - 3.75
Cheese - 1.12

And assuming the tax percent is 13%.

Everything seems to be ok, if you use only one method (aka, sum total + tax, or each item + items for tax), but they differ in end value since you must round.

Explained:

On an invoice/receipt, you can not put a remainder -- you must always round as the person paying can not pay in fractions of a cent, so given the above example in a summary list, would look something like :

Hamburger - 5.24 + Tax: 0.68
Pizza Slice - 3.75 + Tax: 0.49
Cheese - 1.12 + Tax: 0.15

Everything seems ok, if you sum them up, looks perfect with a total of: 11.43

However if you wish to produce a summary (SUM total of items + tax), you end up with a different result -- which is also correct ?

Hamburger - 5.24
Pizza Slice - 3.75
Cheese - 1.12

Tax: 1.31

If you add the rounded taxes from the itemized list, you get 1.32. A difference of a penny.

So the question is how can one produce both a summary and an itemized list that accurately reflects the correct taxes, and which one is actually correct ?

1

There are 1 best solutions below

1
On

This is a "solution" I just found. I don't really like it, but it "seems" to solve the problem I'm writing this as an answer because it's difficult to create the table in the comments.

First look just at the 3 first columns. It's the data as you gave them.

We see that (Initial price + rounded tax)=10,11+1,32=11,43, while it should be 11,42.

So we have 0,01 more, which has to be reducted. We are looking for the row with the biggest round error which is the 3rd one. So we reduct the 0,01 from this row.

If the error was 0,02 (=2 units) we would choose 2 rows.

     Initial price   tax(13%)  rounded tax   round error   fixed tax
     5,24            0,6812    0,68          -0,0012       0,68
     3,75            0,4875    0,49           0,0025       0,49
     1,12            0,1456    0,15           0,0044       0,14
Sum  10,11                     1,32

Advantages:

  • The client will not complain about the sum of the taxes, which is easier to be observed than the multiplication amount*tax.

Disadvantages:

  • It's not mathematically correct to round down the value 0,1456
  • This will not work in the example of 33,33%. This is the case when the row you are searching (with the largest round error) exists twice (or more). In that case maybe we could choose one in random.

What do you think of this approach? Of course I'd be glad to listen as more "solutions" as possible.