Guide · updated 2026-11-04
Money, decimals and rounding
Why floating point breaks totals, and how to parse, round and total amounts exactly.
Use exact types
0.1 + 0.2 is not 0.3 in binary floating point. Use DECIMAL in SQL and decimal.Decimal or integer cents in Python.
Parse by locale
1,234.50 (en-US) and 1.234,50 (de-DE) are the same amount. Parse with the row's declared locale, treat parentheses as negative only if the rules say so, and quarantine anything else.
Never mix currencies
Totals are per currency. Converting requires a declared rate source and date, and the conversion belongs in a documented step, not in a SUM.
Practise it
- Lesson: Exact decimals for money
- Lesson: Dates need a declared locale
- Exercise: Sum amounts by currency, without converting
- Exercise: Flag large transactions, keep refunds