Engineering
Never store money as a float
A bare floating-point number is a plausible way to lose a cent a thousand times. Money deserves a real type — here is the one we use.
6 min read
Somewhere in most codebases is a column called amount, typed as a float, holding 19.99. It looks harmless. It is not: floating-point cannot represent most decimal fractions exactly, so arithmetic drifts, and the drift compounds over enough rows to matter to an auditor.
Four fields, not one
A monetary value in Sillops is never a lone number. It is an integer count of minor units — cents, pence, yen — paired with an explicit currency code. Nineteen dollars and ninety-nine cents is stored as 1999 and USD, and it is added, split and totaled as integers, where the arithmetic is exact.
Currencies do not add
The second discipline is refusing to add values in different currencies without a conversion. A total that mixes euros and dollars is a bug, not a sum. When conversion is needed we attach the exchange rate that was used and the date it applied, so a figure can always be re-derived and defended months later.
None of this is clever. It is just taking money as seriously as the people who will eventually reconcile it. A cent is small; being wrong about a cent, systematically, is not.