Case Study: A Three-Line Cart Priced in Minor Units, Not Floats
Description and use
The case study demonstrates how integer minor-unit pricing and strict rounding rules eliminate one-cent discrepancies in invoices caused by floating-point arithmetic.
Problem
A cart priced with floating point arithmetic can drift by a cent, causing reconciliation errors with the ledger.
Outcome
The helper produces a deterministic total of 58.42 USD (5842 minor units) for the sample cart, preventing one-cent drift and ensuring finance reconciliation matches the invoice.
Workflow
- Freeze pricing rules and sample numbers in the repository before prompting an agent.
- Write a helper module that defines currency scales, rounding, and validation.
- Implement
invoice_totalto compute net, discount, tax, and total in minor units. - Create tests that assert the expected total of 5842 minor units for the sample cart.
- Run tests locally and on a disposable server to verify consistency.
- Review and reject any changes that alter the frozen rules or sample numbers.
Evidence
A three-line cart can look correct in a demo and still miss the ledger by one cent after tax.
The expected USD total for the sample cart is 5842 minor units, which is 58.42 after the rules above.
You want a pure function that prices one cart in integer minor units and fails closed when the currency scale is unknown.
- Record date: 2026-10-09T15:55:52.485Z