Advertisement
Data Processing

The Rounding Gap: 100,000 Amounts Agree to a Billionth, Then Split by $5.19 on Rounding Alone

Two totals can both be honest and still disagree. In this test, 100,000 decimal amounts were added two ways, and the floating-point total landed...

Two totals can both be honest and still disagree. In this test, 100,000 decimal amounts were added two ways, and the floating-point total landed within a billionth of a dollar of the exact total — a difference no invoice or audit would ever feel. Then the test changed one decision, not the arithmetic: when to round. A second set of amounts, priced to three decimal places, was rounded line by line in one run and rounded once at the end in the other. The two totals differed by $5.19. Nothing was miscounted, dropped or buggy. The gap came entirely from the timing of a legitimate operation, which is why it survives code review and shows up later as an unexplained few dollars between two systems that each believe they added the same bill correctly.

What The Rounding Gap means

The Rounding Gap means the difference between two totals for the same set of amounts that arises solely from when rounding is applied — to each line as it is processed, or once to the final sum — rather than from any error in the amounts themselves. Amounts carried to three decimal places, such as prices quoted in thousandths, cannot all survive conversion to cents unchanged. Each one must give up or gain a fraction of a cent at the moment it is rounded. Rounded individually, those fractions are decided 10,000 separate times, each decision pushing its line to the nearest cent. Rounded only at the end, the fractions first cancel and accumulate against each other inside the exact sum, and a single decision is made on what remains. The two procedures answer slightly different questions, so they return slightly different totals, and neither total is the mistaken one.

This concept is distinct from its near neighbour, the Precision Cliff examined in an earlier batch. The Precision Cliff concerns integer representation: past 2^53, a float64 can no longer represent every integer, so identifiers stored as floats can come back changed. That is a boundary in what a number format can hold at all. The Rounding Gap involves no such boundary and no failure of representation. The amounts here are ordinary decimal prices, well inside every format's range, and the divergence appears even when the underlying addition is effectively exact. The subject is not binary precision but decimal rounding policy: a business decision about the point at which fractional cents are settled, disguised as a purely technical step. Two teams can implement the same specification faithfully, choose different rounding points, and produce totals that will never reconcile.

Adding 100,000 amounts, exactly and in float64

The first part of the test asked the simpler question: how much error does float64 addition itself introduce over a large pile of everyday amounts? The file held 100,000 amount strings. Added with exact decimal arithmetic, they totalled $1,012,939.92. Added in sequence as float64 values, they produced a total whose absolute error against that exact figure was $1.56E-9 — roughly one and a half billionths of a dollar. The relative error was 1.54E-15, which is the scale of the format's own resolution rather than the scale of money. Stated plainly, at this volume and with amounts of this size, float64 accumulation error exists, is measurable with exact arithmetic standing behind it, and is commercially irrelevant. It would not move a cent, a fraction of a cent, or any quantity a payment system is capable of expressing.

That finding deserves emphasis because floating-point summation is often discussed as if large transaction counts must eventually add up to real money lost inside the machine. In this construction they did not. Anyone investigating a reconciliation difference of dollars should therefore look elsewhere first. The interesting divergence was waiting in a place that looks like bookkeeping convention rather than computation: dollars against billionths of a dollar, from the same family of operations, on smaller data.

The Rounding Gap: 100,000 Amounts Agree to a Billionth, Then Split by $5.19 on Rounding Alone

Ten thousand three-decimal prices, rounded two ways

The second part of the test held 10,000 prices written to three decimal places — thousandths of a dollar, the extra digit that appears in unit prices, fuel pricing, per-unit wholesale quotes and any rate that is later multiplied by quantity. Their exact sum, before any rounding to cents, stood at $493,036.719. From that single exact figure, two standard procedures were followed. In the first, each price was rounded to cents individually, and the rounded lines were then added: the total was $493,041.91. In the second, the exact amounts were added first and the sum was rounded once at the end: the total was $493,036.72. The difference between the two totals was 519 cents, which is $5.19, on the same 10,000 prices, with no amount altered, omitted or double-counted in either run.

The mechanism is not mysterious. A three-decimal price ending in a half-thousandth or above rounds up when settled line by line; one ending below rounds down. Across 10,000 lines those decisions do not cancel as completely as the exact fractions do, because rounding discards how close each fraction was to the boundary once the decision is made. Summing first preserves every thousandth until the end, so fractions offset each other before the single final decision. The $5.19 is the residue of 10,000 small decisions made early instead of one made late. Scale turns the residue into money: on a handful of lines the same difference would usually vanish, which is why it passes small tests and only surfaces in production volumes and disputes between a supplier's invoice total and a buyer's recomputed total, each generated by software doing exactly what it was told.

How this was measured

All of the amounts in this exercise were synthetic, constructed inside the measurement script rather than taken from any live ledger: 100,000 decimal amount strings for the summation comparison, and a separate set of 10,000 three-decimal prices for the rounding comparison. The script ran with its seed fixed at 42, so the generated amounts are the same on every rerun. Exact totals were computed with decimal arithmetic, float64 totals by sequential floating-point addition, and both rounding strategies by the script's own deterministic logic, applied uniformly to every amount; no rounding library defaults were left to vary between runs. The exercise measures the behaviour of these arithmetic choices on constructed data. It is not a test of any commercial accounting product, payment platform or invoicing service, and no vendor system was evaluated.

Questions, answered

Is float64 addition over 100,000 amounts a real financial risk? Not on this evidence. The exact decimal total was $1,012,939.92 and the float64 error was $1.56E-9, a relative error of 1.54E-15. That is a real, measurable error and a financially meaningless one. The honest conclusion is the opposite of floating-point panic: at this scale, representation error is the last place to look for a missing cent.

Where did the $5.19 actually come from? From rounding timing alone. Rounding each of the 10,000 three-decimal prices to cents before adding gave $493,041.91; adding exactly and rounding the sum gave $493,036.72. The difference is 519 cents, or $5.19, produced by 10,000 early rounding decisions instead of one late one, with identical input amounts in both runs.

Which of the two totals is the correct one? Neither, in the abstract. Each total is the correct output of its own stated procedure. Correctness here is contractual, not mathematical: the right total is the one produced by the rounding point the parties, the specification or the regulation agreed in advance. A dispute between $493,041.91 and $493,036.72 is a specification gap, not an arithmetic error, and it is settled by naming the rounding point, not by recomputing.

Summary

Across 100,000 amounts, float64 summation missed the exact total of $1,012,939.92 by $1.56E-9, a relative error of 1.54E-15 — present, provable and worth no one's worry. Across 10,000 three-decimal prices, the choice of rounding point moved the total by $5.19, between $493,041.91 rounded line by line and $493,036.72 rounded at the end. The Rounding Gap is therefore a policy difference wearing the clothes of a computing error. Systems that must agree on money need to agree, explicitly and in advance, on where rounding happens, because arithmetic alone will not make that decision for them, and at volume the undecided decision is worth real dollars.

Sources

Know someone who needs this? Share it.

Advertisement