RESIDUAL CENT

Round the whole once, then share it out

L215 MINMONEY
PREDICT

An Owoleaf split request divides a ₦100.00 bill equally between Chidi, Folake and Ifeoma. The code rounds each share half-up to the kobo, then switches to banker's rounding (half to even) to be safe. What do the three wallets pay in total?

Money is stored in whole minor units. The naira’s minor unit is the kobo, a hundredth of a naira. Most exact shares land between two kobo, so something rounds. Round every part on its own and the rounding errors do not cancel: the parts miss the total by up to half a kobo per part.

The fix is a rule about where you round. Round the whole once. Then share it out with largest remainder: floor every exact share, and give the leftover kobo one each to the shares with the biggest fractions. The parts now sum to the total by construction. Someone gets the extra kobo: decide who in writing and post it as its own entry, so the books in PAYMENT LEDGER still sum to zero.

▶ SIMULATION
SPLIT ₦100.00 3 WAYS
Chidi: —
Folake: —
Ifeoma: —
exact share 3333.3333… kobo
POLICY
—
SPLIT: BILL − SHARES
—
FX: CHARGE − LINES
—
USD INVOICE AT ₦1,531.2516
annual plan $24.99 → 3826597.7484 kobo → —
extra storage $12.50 → 1914064.5000 kobo → —
seat 1 $4.99 → 764094.5484 kobo → —
seat 2 $4.99 → 764094.5484 kobo → —
SMS add-on $0.99 → 151593.9084 kobo → —
backup add-on $0.99 → 151593.9084 kobo → —
charge: — · lines: —
last stepnothing has run yet
✓ the shares add up to the bill✓ the naira invoice lines add up to the naira charge
SCHEDULE
01[LEDGER]policy: half-up per line
02[SPLIT]split the bill into one share per wallet
03[LEDGER]post: debit each wallet its share, credit the merchant the bill
04[FX]convert the six invoice lines to naira
05[FX]convert the invoice total: the amount the card is charged
06[LEDGER]post: the invoice lines against the charge
07[LEDGER]report
Start of half-up per line scenario. 7 steps.
// Round every part on its own.
share = round(bill / n)            // 10000 / 3 → 3333, three times
for line in invoice:
  line.ngn = round(line.usd * rate)  // six roundings
charge = round(invoice.usd * rate)   // a seventh, independent rounding
// sum(shares) != bill, sum(lines) != charge.
// Banker's (half-even) rounding changes only exact ties: less bias, same gap.

Watch the two gaps in the middle column. HALF-UP PER LINE loses a kobo on the split and its six converted invoice lines come to 2 kobo more than the card charge. BANKER’S PER LINE changes one line, the $12.50 that lands exactly on 0.5 kobo, so the invoice gap shrinks to 1 kobo and the split gap does not move. The fix keeps both gaps at 0, and Chidi carries the residual kobo because the three remainders tie and he is first on the bill.

BREAK IT NOT YET

At ₦100.00 split three ways, half-up rounding loses a kobo. Move the bill and the number of wallets until half-up per share does the opposite: the wallets are debited more than the bill.

GOAL: the shares add up to more than the bill

Banker’s rounding earns its place elsewhere. Over thousands of roundings, half-up pushes every tie upwards and the total drifts one way; half-even sends half the ties each way, so the drift averages out. That is a cure for bias. Vancouver’s was the extreme case, truncation pushing every result down; any round-to-nearest removes most of it, and half-even removes the tie-shaped rest. It is not a cure for parts that must sum to a whole. Notice too that in the fix the two identical $4.99 seats get different naira amounts, ₦7,640.95 and ₦7,640.94. That is the price of an exact total. Say so on the receipt rather than hiding it.

FIX IT NOT YET

Rewrite allocate(total, weights). It gets a non-negative integer total in kobo and an array of non-negative integer weights (at least one above zero). Return integer parts that sum exactly to the total, where each part is the floor or the ceiling of its exact share total × w / W, and the extra kobo go to the parts with the largest remainders. The grader runs equal splits, invoice lines, zero weights and many small lines.

Minor units and currencies looks at the unit itself: the kobo has two decimal places, and not every currency does. The same quoted rate, ₦1,531.2516 per dollar, is the USD/NGN mid in FX arbitrage, where a stale cross rate makes a loop pay.

Mental model:

Rounding is a decision about the whole, not about each part. Round the total once, then allocate it with largest remainder so the parts sum to it exactly, and post the residual to a party named by a written rule. Banker’s rounding reduces bias across many roundings; it never makes independently rounded parts add up.

IN PRODUCTION

Split bills and group payments, instalment plans (₦100,000 over three months), tax and fee lines on an invoice, multi-currency receipts, pro-rata refunds, interest shared across accounts, and the reconciliation report that shows a few kobo nobody can explain.

IN INTERVIEWS

“Split ₦100 between three people” or “Implement allocate(total, ratios).” Show that independent rounding loses or creates a unit, then floor and hand out the remainder by largest fraction, with a fixed tie-break. Keep money in integer minor units, say that banker's rounding reduces bias but does not close the gap, and say where the residual is booked.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.

USED IN

Chapters that build on this lesson.

NEXT: DOUBLE SPEND →