Invoice Total Changes Due to Premature Per-Line Rounding
Level 2 · node · Correctness · Incorrect rounding boundary in aggregation
Scenario
A usage billing service multiplies usage entries by unit prices. The billing rule requires summing unrounded amounts before rounding the final total to cents, but the implementation rounds each line first.
Requirements
Sum raw line amounts and round only the final total to two decimal places. Return zero for empty input and preserve correct integer and single-line totals.
Acceptance criteria
- Small line amounts are rounded only after summation
- Empty input totals zero
- Whole-number amounts are preserved
- A single line is rounded to cents