Why Monetary Amounts Should Never Be Binary Floating Point
Last updated: November 29, 2026
Quick Overview
Explain why storing and computing payment amounts as double-precision floats causes defects, and describe how you would represent money, round it and convert between currencies in a Java or Python service.
Citi
November 29, 20260
0
0 solved
Explain why storing and computing payment amounts as double-precision floats causes defects, and describe how you would represent money, round it and convert between currencies in a Java or Python service.
Citi's payment and ledger services are mostly Java, and an amount that drifts by a cent across millions of postings becomes a reconciliation break and an audit finding. Interviewers use this to confirm you understand number representation and the rounding rules a bank actually applies.
What the Interviewer Expects
- Explain that most decimal fractions have no exact binary representation
- Show a concrete failure such as 0.1 + 0.2
- Recommend integer minor units or a decimal type with explicit scale
- Name a rounding mode and when to round
- Handle currencies with 0 or 3 decimal places
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- When would you use banker's rounding (HALF_EVEN) instead of HALF_UP?
- How do you split $100 into three payments that sum exactly?
- How should amounts be serialized in a JSON API?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
The interviewer wants three things: why floats fail, what to use instead, and the rules for rounding and FX conversion that keep a ledger balanced....
High-Level Design
A double stores a binary fraction. Values like 0.10 are repeating fractions in base 2, so the stored value is slightly off. Single operations look fine when printed, but sums over thousands of posti...