Debug a Rounding Error in Monthly Credit Card Interest
Last updated: November 29, 2026
Quick Overview
A monthly interest job computes round(balance * apr / 12, 2) with Python floats and customer statements are off by a cent on some accounts; find the cause, fix it, and write tests that would have caught it.
J.P. Morgan
November 29, 20260
0
0 solved
A monthly interest job computes round(balance * apr / 12, 2) with Python floats and customer statements are off by a cent on some accounts; find the cause, fix it, and write tests that would have caught it.
J.P. Morgan phone screens for Chase consumer and card teams often include a practical debugging question about money handling, because penny errors across millions of accounts become regulatory and reconciliation problems. The interviewer checks that you know binary floats cannot represent most decimal amounts, that Python's round uses banker's rounding, and that you test boundaries rather than happy paths.
What the Interviewer Expects
- Explain why 0.1 and 2.675 are not exact in binary floating point
- Use Decimal (or integer minor units) built from strings, never from floats
- Choose and document an explicit rounding mode tied to the product rule
- Write tests at the exact half-cent boundary
- Mention reconciliation against the ledger to catch drift
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
- Should interest be rounded each day, each month, or only on the statement?
- How would you store APR to avoid the same issue?
- How would you roll the fix out without changing already-issued statements?
- How do you handle currencies with zero or three minor units?
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
Interest must match the card agreement to the cent, be reproducible, and match what a downstream ledger computes. Inputs arrive from the ledger as decimal strings like "101.00" and "0.06"....
High-Level Design
Two separate bugs are hiding in one line. First, floats are binary, so 2.675 is stored as 2.67499999... and round(2.675, 2) returns 2.67. Results depend on accidental representation error. Sec...