Skip to content
NewKabaido Inspect is live: know every manufacturer on your patch before you knock.See Inspect

Why quoting software should count in pence

Binary floating point cannot hold a tidy decimal exactly. Charming in a tutorial, less so on a 4,000-line quote. A short defence of integer money.

Engineering notesKabaido2 min read

Type 0.1 + 0.2 into a JavaScript console and it answers 0.30000000000000004. Charming in a tutorial. Less charming on a 4,000-line quote, where the same arithmetic runs thousands of times before anyone reads the total.

Why floats cannot hold money

Computers store ordinary decimal numbers in binary floating point, and most tidy decimals have no exact binary form. One tenth in binary is a repeating fraction, the way one third is in decimal, so the machine stores the nearest value it can represent and the error tags along through every subsequent operation. The classics are worth seeing once.

Standard double-precision floating point arithmetic, exactly as a JavaScript console reports it.
You writeYou get
1.03 - 0.420.6100000000000001
0.1 * 30.30000000000000004
1.005 rounded to 2 places1.00, because the stored value sits fractionally below 1.005
Binary floats0.1 + 0.2= 0.30000000000000004drift compounds line by lineInteger pence10 + 20= 30, exactlyround half-up once, at displayMoney stored as whole minor units with its currency; formatting happens at the edge
The same sum in binary floats and in integer pence. One of these is exact every time.

Integers and minor units

The boring, correct answer has been industry practice in payments for decades: store money as a whole number of the currency's minor unit, alongside the currency code. £149 is 14900 pence. Integer addition and subtraction are exact, comparisons are exact, and a column of a million line totals sums to the same value every time on every machine. The currency travels with the amount because the minor unit is not always two digits: yen has none and Bahraini dinar has three, so an amount without its currency is not even interpretable.

Round once, at the edge

Calculation still needs fractions. A unit price times a quantity times a discount percentage produces values finer than a penny, and that is fine, as long as the fractions live in decimal arithmetic during the calculation and rounding happens once, at the final display. Round in the middle and the order you round in becomes part of the price.

Three lines at £10.995 each, in exact decimal arithmetic, rounded half-up at different points.
PolicyWorkingTotal
Round each line, then sum£11.00 + £11.00 + £11.00£33.00
Sum, then round once£32.985 rounded half-up£32.99

Neither policy is wrong in the abstract. What is wrong is not choosing, because the moment your quote and your customer's ERP round in different places, a penny of disagreement appears on its own line in somebody's reconciliation report and an email thread starts that costs more than the penny ever did. Pick one rule, write it down and apply it everywhere.

A quote is a promise about a number. The arithmetic behind it should be the most trustworthy thing in the building, which is why the first engineering decision in any quoting system worth the name is also the least glamorous one: count in pence.

Sources and method

More from the blog

Engineering notes3 min read

What a plasma cut chart actually encodes

A clean plasma part and an evening of grinding dross differ by three numbers per material and thickness. Where they come from and why they drift.

Read the post
Engineering notes3 min read

What a balustrade quote has to calculate

A metre of balustrade looks like a price per metre. It is a structure with a load case, and the load case moves the price. The working, in order.

Read the post
Engineering notes4 min read

The soft jaw order hiding in a chuck model

A soft jaw enquiry looks like two words and a chuck size. The serration, the jaw envelope and the material are all implied. How a seller reads one.

Read the post

Put the research to work

Kabaido reads requests the way the engineers in these posts do: structured, cited and honest about gaps.