Decisions
0001 · Integer cents
Money as integer minor units, split with the largest-remainder method.
Status: Accepted · 2026-11
Context
Version 1 stored prices as floats and divided them per person (item.totalPrice / consumers). Totals were shown with toFixed(2), so three people splitting R$ 100 each saw R$ 33,33 and the group came up one cent short. With service charge and fees layered on top, the per-person sum regularly disagreed with the bill by a few cents — exactly the kind of thing people argue about at a table.
Decision
- Every amount is an integer number of the currency's minor units, everywhere in the model and the engine.
- Splitting uses the largest-remainder (Hamilton) method with a positional tie-break:
allocate(total, weights)always returns parts that sum tototal, and the same input always yields the same output. - Percentages are stored as basis points. Group-level percentages are rounded once and then allocated, so the line on the receipt equals the sum of the parts.
Consequences
- The cent invariant (
Σ person totals = grand total) holds by construction and is asserted in tests. - Someone gets the extra cent. It is deterministic and documented, which is fairer than it vanishing.
- Parsing and formatting must go through
lib/money.ts; ad-hoc arithmetic on display strings is a bug.