Rounding currency values

183 Views Asked by At

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.

2

There are 2 best solutions below

2
On BEST ANSWER

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$.

0
On

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.