Two replacement brackets cost $19.95 each. At a sample tax rate of 8.25%, putting both on one invoice line gives a total of $43.19. Give each bracket its own line and the total comes to $43.20. Both invoices round the tax on each line to the nearest cent.
| Invoice lines | Subtotal | Tax | Total charged |
|---|---|---|---|
| One line, quantity 2 | $39.90 | $3.29 | $43.19 |
| Two lines, quantity 1 each | $39.90 | $3.30 | $43.20 |
On one line, $39.90 × 0.0825 gives $3.29175 of tax, which rounds to $3.29. On separate lines, each bracket carries $1.645875 of tax, which rounds to $1.65. That extra cent becomes interesting if the customer returns the brackets on different days.
One bracket on Monday, the other on Friday
The two-line invoice already records $1.65 of tax against each bracket. Each return can reverse its own $21.60 line.
The single-line invoice has just $3.29 of tax to refund. If the returns code starts from the unit price and calculates the tax afresh on Monday and Friday, it pays out $21.60 twice. The customer gets $43.20 back on a $43.19 charge.
One way to split the tax on these two identical units is to round the cumulative share. After one return, half of the original 329 cents rounds to 165 cents. After both returns, the full 329 cents is due. Friday’s refund gets the 164 cents left over.
import assert from 'node:assert/strict'; const unitNetCents = 1995n; const unitsSold = 2n; const originalTaxCents = 329n; function refundToDate(unitsReturned) { const numerator = originalTaxCents * unitsReturned; const taxToDate = (numerator + unitsSold / 2n) / unitsSold; return unitNetCents * unitsReturned + taxToDate; } const first = refundToDate(1n); const second = refundToDate(2n) - first; assert.equal(first, 2160n); assert.equal(second, 2159n); assert.equal(first + second, 4319n); When testing a refunds endpoint, send two separate requests against the same saved invoice. A test that returns both brackets in one request can pass even when the partial-return path pays out an extra cent.
An AI agent drafted this article and ran the Node.js example. The two invoice totals were also checked against the invoice calculation code using the sample amounts above.
