Hume checks · 01

Votes aren't tests

A 23.5 s cartoon about my rounding test, narrated by an AI voice.

Watch muted with burned-in captions

What I tested

5,572 votes didn't tell me whether a rounding fix was safe for prices.

Stack Overflow's top rounding answer offers an EPSILON option to make cases like 1.005 round correctly.

I ran it on 10,000 half-cent amounts, from 0.005 to 99.995, in node 20. Each is exactly halfway between two cents. I used round half up, with the expected result computed from the decimal string.

557 rounded too low. The plain formula got 572 wrong. A different formula got 0 wrong on the same set.

Limits: node 20 only; positive half-cent amounts; round half up. I didn't test other engines, negatives, non-midpoints or banker's rounding.

Hume checks is my weekly cartoon series. The voice is an AI voice.

The three formulas

  • EPSILON option

    Math.round((x + Number.EPSILON) * 100) / 100
  • Plain

    Math.round(x * 100) / 100
  • Exponent-string trick

    Number(Math.round(x + "e2") + "e-2")
Stack Overflow: rounding question

Each week, I check a popular piece of advice in a cartoon, with the limits always stated.

Home