// blog

Why Your Old Program's Invoice Totals Are Off by a Cent

Many older programs keep money as floating-point numbers and round only when they display it. Each tax line is rounded, and the total is rounded on its own, so the printed total can differ by a cent from the printed subtotal plus taxes. In a test of 100,000 random invoices with Quebec’s two taxes, the old program’s total was a cent off 23,423 times. The fix is to round each tax to the cent and add the rounded parts, which changes some totals by a cent: an owner has to agree to that.

Last updated 2 min read

An invoice in a browser

Bookkeepers know this one: an invoice where the subtotal, the two taxes and the total don’t quite add up. It’s a cent off, and nobody can say why.

We saw it while moving Virtual Salesman 3, a Windows invoicing program from 2006, to the web.

Why it happens

The old program kept money as 32-bit floating-point numbers, which can’t hold most cents exactly: 19.99 is stored as 19.9899997… It worked out each tax at full precision and rounded only when it showed the number. So:

  • the federal tax is shown rounded,
  • the state tax is shown rounded,
  • and the total is worked out from the unrounded taxes, then rounded on its own.

When both taxes round the same way, the total ends up a cent away from the sum of the lines above it.

How often

We re-created the old program’s arithmetic exactly. It gives the very bits the program saved in its own files. Then we ran 100,000 random invoices through it, with Quebec’s federal and provincial taxes. On 23,423 of them, 23%, the printed total was a cent away from the printed subtotal plus taxes.

What the web version does, and why it’s a decision

The web version keeps money as exact decimals, rounds each tax to the cent, and makes the total the sum of what’s printed. Every invoice adds up.

That’s a change: on 23,392 of the same 100,000 invoices, the new total is a cent different from what the old program would have printed. For new invoices that’s an improvement. But anyone comparing old and new reports will see it, so it’s agreed with the owner before the switch, not discovered after.

If you’re replacing an old program

  • Ask how it rounds. Per line, per tax, or only at the end. Then decide what the new one should do.
  • Test with real invoices the owner knows, and compare every line, not only the total.
  • Write down every intended difference, like this one, so nobody is surprised by the first report.

The full case study shows the old arithmetic, the new one and the tests. Running an old invoicing program? Tell us about it.