Round a cash total the way the post-penny rules actually work
round_cash_totalSettle a transaction under post-penny cash rounding: exact subtotal, tax on the exact subtotal, then round the final total to the nearest nickel — and only for cash.
Use this for any "what does X round to" or "what do I owe in cash" question. Four things are wrong in most explanations of this, and each one changes the answer:
CASH ONLY. Card, EFT, and gift-card payments are still priced to the cent. The same basket legitimately comes to two different amounts by tender. If asked about a card payment, do not round.
THE TOTAL, NOT EACH ITEM. Rounding per item multiplies the effect by the basket size. Five items at $0.99 total $4.95 — already a nickel, no rounding — where per-item rounding would collect $5.00.
AFTER TAX. Tax is computed on the exact subtotal and the rounding comes last. Rounding the base first changes the tax owed.
THE DIGIT DECIDES. 1, 2, 6, 7 round down; 3, 4, 8, 9 round up; 0 and 5 stand. Do not reason about "nearest" from scratch, and do not assume rounding is always up.
Input: pass subtotal as a dollar string ("19.99") or items as a list. A NUMERIC amount is read as CENTS and a STRING as dollars — 1999 and "19.99" are the same amount, 19.99 as a number is refused. Pass taxRatePercent as a percentage (8.25, not 0.0825); rounding depends on it, so omitting it usually gives the wrong nickel. tender is cash or card, default cash. rule is symmetric (default), always-down, always-up, or none.
Returns: the exact subtotal, tax, exact total, the rounded amount due, the signed delta, which digit decided it, warnings, and a disclaimer field.
THIS IS NOT LEGAL OR TAX ADVICE. There was no federal rounding law as of September 2026 and state law varies. Do not tell a user what their jurisdiction requires — report the arithmetic and the caveats.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rule | No | symmetric (default) is the Common Cents Act and Canadian method. always-down is Indiana's rule for cash payments of TAX, not a retail rule. always-up is not law anywhere for retail and is here only to quantify it. none is what a card gets. | |
| items | No | Line items, totalled in exact cents. Rounding applies to the TOTAL only. | |
| tender | No | Default cash. A card is NEVER rounded — if the user is paying by card, the exact total is the answer and any rounding rule is ignored. | |
| subtotal | No | The pre-tax subtotal. Use this or `items`. | |
| taxRatePercent | No | Percentage, e.g. 8.25 — not 0.0825. Supply it whenever it is known: rounding happens after tax, so the rate decides which nickel the total lands on. |