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 ?
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.
Advantages:
Disadvantages:
What do you think of this approach? Of course I'd be glad to listen as more "solutions" as possible.