1

If I have a receipt with the following:

  • 4.37
  • 4.37

Each item discounted at 10%

  • 4.37 * 10% = .44. rounded from .437

  • 4.37 * 10% = .44 rounded from .437

total discount .88

  • subtotal is 7.87 rounded from 3.933 + 3.933 = 7.866

  • 7.87 * 5.5% tax = .43 rounded from .43285

  • Grand Total is 7.87 + .43 = 8.30

However the physical receipt in my hand shows the discount to be .87.

  • D: .87
  • S: 7.87
  • X: .43
  • T: 8.30

How can this be?

I'm trying to write an java/android app that prints a receipt but my numbers do not always match the physical receipts I compare it against. I suspect it has something to do with rounding. How should I be rounding these values? Btw, I'm using the Java BigDecimal.

KiloJKilo
  • 111

2 Answers2

0

If I understand the question correctly, I'm guessing you should round after the calculations, not at each step. So the total discount is

$$2\cdot 4.37\cdot 0.1 = 0.874 $$

and rounded to the correct number of decimal places is $0.87$.

Eff
  • 12,989
  • So in other words, discount the total of the products, not each individual line item and then add those up? – KiloJKilo Mar 15 '16 at 12:07
  • Well, what I mean, and it might be what you mean as well, is that you should do the computations with the true (i.e. not rounded) numbers, and only finally when you display the discount do the rounding. So yes, add up all the discounts and then round. – Eff Mar 15 '16 at 12:13
0

The reason for this is because the discount for the first product valued at $4.37$ is $$4.37 \times 0.1 = 0.437$$

Likewise the discount for the second product valued at $4.37$ is also $0.437$.

Hence, the total discount given is $2 \times 0.437 = 0.874$. Therefore, the discount is $0.87$ rounded to $2$ decimal place.