Invoice discount rounding depends on line count
Unranked practice · 100 points
Ticket
Discounts are integer basis points. Calculate half-up rounding once on the invoice subtotal, not independently on each line. All calculations must preserve integer-cent precision within the safe integer range.
Workspace rules
- Edit surface
- src/pricing.js
- Protected
- test/pricing.public.test.js
- Public tests
- test/pricing.public.test.js
Rubric
- itemized-subtotal20 pts
- single-line-discount-half-up20 pts
- multi-line-discount-once40 pts
- zero-discount-large-total20 pts
Gates: pricing-input-validation
Editorial
Show editorial (spoiler)
## What is wrong Rounding each line separately lets per-line fractions accumulate, so the same discount produces different totals depending on how the invoice is split. Very large subtotals can also exceed safe integer arithmetic. ## Fix Sum the line subtotals first, apply the basis-point discount exactly once with half-up rounding, and keep the result in integer cents. Reject inputs that would exceed `Number.MAX_SAFE_INTEGER` instead of silently losing precision.
Sign in to open the account-gated workspace. The practice agent and submissions arrive in the next slices; this workspace is untimed and unranked.