Skip to content

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

Teaching software to read like a domain engineer

A general AI model knows what a milling cutter is. It does not know your milling cutter. What it takes to ground a model in a real industrial domain.

Read the post
Inside the work2 min read

What an RFQ actually contains

An RFQ looks like a document. It is closer to a scattered set of claims, each hiding somewhere else. How engineers read one, and how software should.

Read the post
Industry research2 min read

You cannot hire your way out of a quoting backlog

The UK posts about 900 new application engineer adverts a month against a 27,200 base. What continuous re-hiring of a hard-to-define role really signals.

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.