Build a Money Value Type That Never Loses a Cent
Last updated: November 29, 2026
Quick Overview
Explain why payroll code should never store amounts as binary floats, then implement a small immutable Money type that supports parsing, addition, subtraction, multiplication by a tax rate and display.
Gusto
November 29, 20260
0
0 solved
Explain why payroll code should never store amounts as binary floats, then implement a small immutable Money type that supports parsing, addition, subtraction, multiplication by a tax rate and display.
Every Gusto paycheck is a sum of earnings, withholdings and deductions that must reconcile exactly against bank debits and tax filings. A fundamentals question in this style checks whether you understand floating point error and can design a value object that makes the wrong thing hard to do.
What the Interviewer Expects
- Explains binary floating point representation error with an example
- Stores amounts as integer minor units or Decimal
- Makes the type immutable and currency aware
- Rounds once, at a defined step, with an explicit rounding mode
- Rejects mixing currencies or adding raw numbers
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
- Where exactly should rounding happen when computing Social Security on a paycheck with ten earning lines?
- How would you persist this type in MySQL and through a JSON API?
- How would you support currencies with zero or three minor digits for international contractor payments?
- How would you split one amount across several accounts so the parts sum to the whole?
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
A binary float cannot represent 0.10 exactly, so 0.1 + 0.2 is 0.30000000000000004. Over thousands of line items and many employees those errors leak into net pay, tax liabilities and the ACH debit...
High-Level Design
Store integer cents. Parse from strings, never floats, and reject inputs with more precision than a cent. Arithmetic between two Money values checks currency. Multiplying by a rate (such as 6.2 perc...