QA Interview Hub · Knowledge base · Quizzes · Українська

QA Fundamentals › Fintech specifics

What should you check in calculations with money?

Calculations with money are checked in five places: data type, rounding, allocation, currency and display. Money is not computed in float, because 0.1 has no exact binary form; it is stored as integers in minimal units or as DECIMAL. The rounding rule comes from the requirement. Splitting an amount (100.00 into three) must hold an invariant: the parts add up to the whole and differ by at most one kopeck.

QA Fundamentals · Fintech specifics

A 100 UAH bill split between three people adds up to 99.99. Where did the cent go?

A café bill of 100.00 UAH is split between three people. The app shows three payments of 33.33, together 99.99. One kopeck belongs to nobody: not the café, not the guests. On one bill it is a trifle, but on a million operations a day it is a gap in accounting that takes weeks to find. This lesson is about where money "breaks" (number representation, rounding, allocation, currencies, display) and what QA checks in each place.

How it works and why. A computer stores fractional numbers in binary (float, double), and most decimal fractions, 0.1 among them, have no exact binary form. For physics that is fine, for money it is not: the law requires a cent to be a cent. So money is stored and calculated in one of two ways: as integers in the minimal currency unit (kopecks, cents) or as an exact decimal type (DECIMAL in the database, BigDecimal in Java). This is what float does:

0.1 + 0.2          // 0.30000000000000004, not 0.3
0.1 * 3            // 0.30000000000000004
1.005.toFixed(2)   // "1.00", not "1.01"
Math.round(-2.5)   // -2 (while Math.round(2.5) gives 3)

A difference in the seventeenth digit is invisible on screen, because the sum is rounded for display. It shows up in comparisons ("balance >= amount" does not hold), in report totals and in the accumulation over thousands of operations. There is also a transfer trap: if an API returns an amount as a number with a dot, the client parses it as a double and the error comes back. So an amount in JSON is either an integer in minimal units together with a currency code, or a string.

One amount in two representations

Risky

float: 0.1 * 3

The result is 0.30000000000000004. Comparing with 0.3 is false, and a cent-sized difference piles up in reports.

Reliable

integer cents: 10 * 3

The result is 30, exactly. The dot appears only on screen, when the number is formatted for a human.

Figure 1. The same calculation in float and in minimal units: precision is solved by the data type, not by rounding "by eye".

Now what exactly to test. Errors concentrate in five places:

Where it breaksSign in a testWhat to check
Data typeA cent "appears" or vanishesAmounts with 0.1, 0.2, 0.7; the sum of many lines; values in the DB and in the API
RoundingA total differs by a cent from a manual calculationThe rule (up, to nearest, to even) and the step where it is applied
AllocationThe sum of parts differs from the wholeDivision by 3, 7, into percentage parts; where the remainder goes
CurrencyExtra or missing decimal placesThe minor unit by ISO 4217; conversion and the rate
DisplayA different look on different screensSeparators, currency symbol, negative amounts, very large numbers

Rounding: the rule and the step. There are several rules. Half-up (0.5 goes up) is familiar from school. Banker's rounding (half-even) rounds a half to the even neighbour, so 2.5 becomes 2 and 3.5 becomes 4, and the systematic drift in totals disappears; it is standard in some banking systems and in many libraries. Which rule applies is set by a requirement or a contract, not by QA. Even more important is the step: round every line of a bill or only the total. The difference shows even in a small example.

The same bill, rounded at different steps

Per line

3 items at 0.15, tax 10%

Tax on one line 0.015 → 0.02. Together 0.06. Bill total 0.51.

On the total

Sum 0.45, tax 10%

Tax 0.045 → 0.05 (half-up). Bill total 0.50.

Figure 2. Both approaches are legitimate, but must give what the requirement says. A cent of difference is multiplied by the number of bills.

Example: splitting 100.00 UAH three ways, from the bug to the fix. The initial logic divides and rounds every part separately: 100 / 3 = 33.333… → 33.33 for everyone. A test with the expectation "the sum of parts equals the whole" fails: 99.99 against 100.00. One kopeck belongs to nobody. The fix works with integer kopecks: everyone gets the base and the remainder is handed out one kopeck at a time:

function split(totalMinor: number, parts: number): number[] {
  const base = Math.floor(totalMinor / parts);
  const rest = totalMinor - base * parts;
  // the remainder goes out one minor unit at a time
  return Array.from({ length: parts }, (_, i) => base + (i < rest ? 1 : 0));
}

split(10000, 3); // [3334, 3333, 3333], the sum is exactly 10000

Now the sum matches by construction, and the test checks exactly the invariant: for any amount and any number of parts the sum of parts equals the whole, and parts differ by at most one kopeck. One such test with a set of values (100.00 by 3; 0.01 by 2; 0.02 by 3; 1,000,000.00 by 7) catches a whole class of errors. A few boundary cases that matter for money: 0.00 (is it allowed), 0.01 (the minimum), the maximum from the requirement, and crossing the integer type limit: 2,147,483,647 kopecks is 21,474,836.47 UAH, and at exactly such an amount a 32-bit integer overflows. Negative values (refunds, adjustments) are a separate class too, because Math.round(-2.5) gives -2, not -3, and the rounding rule for minus is easy to break.

Currencies. The number of decimal places depends on the currency: the hryvnia and the dollar have two, the yen zero, the Bahraini dinar three (ISO 4217). So "always two places" is wrong, and a check of "100.5 JPY" must reject or round it by the rule. In a conversion the rate has many decimal places; the right order is to compute with full precision and round once at the end, not at intermediate steps. Separately it is clarified at which moment the rate is fixed: at payment creation or at charging (more in the lesson about payment risks).

Limits and alternatives. Float is not forbidden everywhere: for analytics, charts and estimates an error in the seventeenth digit does not matter, and a ban there would be excessive. The rule concerns money that moves, is stored and is shown as a debt or a balance. Alternatives to integer kopecks: decimal types of the language (BigDecimal, decimal) or libraries such as Decimal.js; the team chooses, and QA checks that the chosen solution is in place everywhere from the UI to the DB, because one float link spoils everything. If the requirement says nothing about the rounding rule, that is a question for the analyst, not a place for your own assumption.

Common mistakes.

  • Checking only "nice" amounts like 100.00 and 250.00: errors live in 0.1, 0.7, 19.99 and in sums that divide with a remainder.
  • Comparing the result with the expected value in a test through float: the test itself introduces the error. Expectations are set in kopecks or as a string.
  • Looking only at the screen: display rounds, and an extra cent is visible only in the API response, in the DB or in a report.
  • Not asking about the rounding step: two "correct" results differ by a cent, and the argument goes on without a requirement.
  • Forgetting negative amounts and refunds: rounding behaves differently there.
  • Assuming two decimals for all currencies: the yen, the dinar and cryptocurrencies have other rules.

Check yourself

An order of 0.10 + 0.20 UAH. An autotest compares total === 0.3 and fails, although the screen shows "0.30 ₴". Is it a product bug or a test bug, and what do you do?

Answer

Most likely the product calculates in float while the screen shows a rounded value. It is a product bug, and the test only exposed it. The fix: calculate in kopecks or DECIMAL, and in the test expect 30 kopecks. If the API response contains 0.30000000000000004, we see the same problem at the contract level.

An amount of 100.00 UAH is divided between three recipients and the system returns 33.33 + 33.33 + 33.33. What else besides the sum do you need to ask and check?

Answer

Who gets the remainder of 0.01 by the requirement (the first, the last, a random one, a separate account), whether this choice is stable on a repeat, whether a kopeck is lost with other divisions (7, 0.02 by 3). The invariant: the sum of parts equals the whole, and parts differ by no more than 0.01.

In an interview. Junior: Money must not be calculated in float, because 0.1 + 0.2 does not equal 0.3. It is stored as integer kopecks or as a decimal. I check rounding, the number of places for each currency, that an allocation adds up to the kopeck, and that display is right, including negative amounts. Middle/Senior: I check invariants, not single examples: the sum of parts equals the whole, a total matches in the UI, the API and the DB. I separately ask for the rounding rule and the step where it applies, because per line and on the total the result differs by a cent. I take boundary amounts: 0.01, the maximum, 32-bit integer overflow, negative values, currencies with 0 and 3 places. If the requirement is silent about rounding, that is a question for the analyst, not my assumption.

More articles in this chapter