A penny is the smallest error a calculator can make, and somehow it is also the most embarrassing one. If your time card says you earned $802.50 and the total at the bottom says $802.49, nobody cares that 99.9% of the maths was right. They care that the number is wrong, because pay is one of those things where being almost right is the same as being wrong.

I found this out on my state overtime pages. Fifty-one of them, one per state, all sharing the same JavaScript. The same code, the same formula, the same rounding. And on two of them, the totals were a penny out.

The cause was not the state rules. It was floating-point arithmetic, the oldest trap in browser JavaScript. A computer stores 0.1 as something very close to 0.1 but not quite, so 0.1 + 0.2 comes out as 0.30000000000000004. Multiply a wage by a fraction of an hour, add a few of those together, and sooner or later a value lands on the wrong side of a rounding boundary. Most of the time the error stays invisible, hidden behind the second decimal place. On two pages, the numbers lined up just wrong enough for it to show.

What made it hard to spot was that the rest of the page looked fine. Every line item rounded cleanly. The hourly rate was right, the hours were right, the overtime rate was right. Only the total was off, by one cent, and only on those two pages. That is the nasty part about rounding bugs: the inputs are all correct, and the answer is still wrong.

The first version of my code rounded each line, then added the rounded lines together. That sounds sensible, and it is what most people do first. But it means the total is a sum of rounded numbers, and a sum of rounded numbers can drift from the true total by a cent. The fix was to do it the other way round: add the exact values first, and round once, right at the end, when the number is shown. One rounding step, at the last possible moment.

Even that was not quite enough on its own. JavaScript's toFixed() looks like the answer, but it rounds on the floating-point value, which may already be 802.4949999999999 by the time you ask. So I switched the money maths to integer cents wherever the page allows it: multiply the dollars by 100 as early as possible, do the arithmetic in whole cents, and only divide back by 100 for display. There is no such thing as a fraction of a cent in a pay packet, so there should not be one in the code either.

The second part of the fix was a test. Every state page now gets its totals checked by hand against a worked example. I type in a known week and a known rate, and I check the gross against a calculator I trust. It sounds slow, and it is, but it caught the penny errors, and it has caught other small slips since. A calculator that cannot be checked by hand is a calculator I do not trust.

The lesson I took away is simple, and it applies to far more than pay sites: round once, round late, and never let a rounded number feed into another calculation. If you round early, the error compounds quietly and shows up in the one place your users actually read — the total.

I write about the build as I go, and the calculators themselves are live on mytimecardcal.com if you want to poke at the maths yourself. Try a week with odd minutes — say 7 hours 23 minutes at $18.75 — and see if the total still comes out clean. That is the test that matters.