“It is only maths; if the formula is right, the answer is right.” That belief is why money bugs survive code review. Money is the one domain where a difference of 3 paise is a defect, because totals must match across the invoice, the ledger, the payment gateway and the bank statement. Let us take the belief apart in three places.

Belief one: a decimal number is a decimal number

Most programming languages store ordinary fractional numbers in binary floating point. Many decimal fractions, including 0.1, have no exact binary form. In Python, adding 0.1 and 0.2 gives 0.30000000000000004. The same happens in JavaScript, Java’s double and most others.

For a single price this is invisible, because the display rounds. It shows up when you compare. A test that asserts a total equals 0.30 may fail, or worse, a check in the application that says “if amount paid equals amount due, mark settled” may silently never fire for certain amounts.

The usual remedies are to store money as integers in the smallest unit (paise), or to use a decimal type such as Java’s BigDecimal or Python’s Decimal. As a tester, ask which one the system uses and look for the places where a conversion sneaks in: a JSON number parsed as a double, a spreadsheet export, a reporting query that casts to float. The risk sits at the boundaries, not in the core.

Test with amounts that expose this, such as 0.10, 0.20, 19.99, 1,00,000.01 and large values like ₹9,99,99,999.99, and check the displayed total, the stored value and the value sent to the payment gateway all agree.

Belief two: rounding is rounding

There are several rounding rules and software picks one by default. “Half up” rounds 2.5 to 3 and 3.5 to 4. “Half even”, often called banker’s rounding, rounds to the nearest even digit when exactly halfway: 2.5 becomes 2 and 3.5 becomes 4. Python’s built-in round uses half even on exact halves, so round(2.5) is 2. Java’s BigDecimal requires you to name a mode, and HALF_UP and HALF_EVEN both exist.

Binary storage adds another twist. Python’s round(2.675, 2) gives 2.67, not 2.68, because the stored value is slightly below 2.675. A decimal type fed the string “2.675” behaves differently from a float fed the number 2.675.

So the question for the team is not “do we round?” but “which rule does the business require, and is it applied everywhere?” Finance may expect half up on invoices while a reporting script uses the language default. Both look correct in isolation. Together they give a one-paisa difference on exactly the amounts that end in a half.

Belief three: tax on each line equals tax on the total

Take a small illustrative bill from a bakery in Kozhikode: 7 packs of a snack at ₹12.50 each, taxed at 5 percent. The pre-tax total is ₹87.50.

  • Tax computed per unit and rounded: 12.50 × 5% = 0.625, rounded to ₹0.63. Seven units give ₹4.41.
  • Tax computed once on the total: 87.50 × 5% = 4.375, rounded to ₹4.38.

Both are defensible calculations. They differ by 3 paise. Multiply by thousands of invoices a day and the difference reaches the ledger. Which one is right depends on the system’s design, and for Indian GST on the rules and the format of the invoice, so confirm with the finance or compliance team rather than assuming. What testing can establish is consistency: the invoice, the e-invoice or return data generated from it, the accounting entry and the amount charged must all follow the same approach.

Discounts add another ordering question. Is a 10 percent discount applied before tax or after? A coupon of ₹50 on a three-item cart: is it spread across items, and if so, how are the odd paise allocated? A split of ₹50 over three items gives ₹16.67, ₹16.67 and ₹16.66, which only works if someone decided where the leftover paisa goes. Refunds make it harder still: refunding one item of three must return a tax amount that, with the others, adds back to the original.

A test approach that fits

Build a small table of hand-computed expected results, using a decimal-safe tool, and cover these shapes:

  • Amounts that land exactly on half a paisa after tax.
  • Quantity above one, where per-unit and per-total methods diverge.
  • Mixed tax rates in one basket (for instance 5 and 18 percent items together).
  • Discount plus tax, in both orders, to confirm the documented one is used.
  • Full and partial refunds, checking that the sum of refunds never exceeds what was paid.
  • Totals compared across screens, PDF, email, API response and database.

Add a property-style check where you can: for any basket, the sum of the displayed line amounts plus tax should equal the displayed grand total. That single assertion catches a surprising share of rounding defects without needing a hand-calculated answer.

Notice what none of these checks needs: a wrong formula. The formula can be perfect and the sum still be off by a few paise, because correctness here includes the order of operations, the rounding rule and the number type. That is the belief we started with, taken apart.

Figures and names in the examples are illustrative.

Leave a Reply

Trending