Invoice Total Skips Per-Line Currency Rounding
Level 2 · node · Correctness · Monetary rounding order error
Scenario
A billing system calculates each usage line from unit price and quantity, fixes it to the currency minor unit in cents, and then builds the invoice total. A single line can look correct, but operations reports that invoices containing several fractional-cent lines can differ by one cent between the sum of displayed line amounts and the invoice total. The service, money helper, and repository are separated.
Requirements
- Each line amount is quantity * unitPrice rounded to cents - The invoice total equals the sum of the finalized line amounts - Lines already resolving to whole cents keep their existing values - With multiple fractional-cent lines, the displayed lineAmount sum equals total - A nonexistent invoice returns null
Acceptance criteria
- Whole-cent lines and their total are correct
- Each fractional-cent line is rounded to cents
- The total for multiple lines equals the sum of rounded lineAmount values
- The total stays consistent when lines with different rounding boundaries are mixed
- A nonexistent invoice returns null