METABYTE
Back to articles

Floats Don't Even Agree with Themselves: The IEEE 754 Nightmare

Why 0.1 + 0.2 != 0.3 and how to survive floating point arithmetic in your code.

8 mai 20261 min read
Floats Don't Even Agree with Themselves: The IEEE 754 Nightmare

Developers, brace yourselves: floating point numbers don't even agree with themselves. A deep dive from Merca Earth reveals an ancient pain — 0.1 + 0.2 in JavaScript stubbornly yields 0.30000000000000004. And it's not a bug, it's a feature of the IEEE 754 standard.

Why does this happen?

It's all about binary arithmetic: decimal fractions like 0.1 cannot be exactly represented with a finite number of bits. It's like trying to write 1/3 in decimal — you get infinite 0.3333... Except with floats, the computer rounds, and magic ensues.

Here are a few ways to keep your sanity:

  • Use integers (count cents instead of dollars).
  • Leverage libraries like decimal.js for critical calculations.
  • For comparisons, use an epsilon (tolerance threshold).
  • Or just accept it and round to the desired precision.

Developers who've faced this in CI or payment processing know: better spend an hour learning IEEE 754 than debug a night deploy gone wrong.

METABYTE studio comment: We too enjoy predictable numbers — especially in fintech apps. If your floats start rebelling, give us a call: we'll tame them with proper libraries and rigorous testing.

NEXT STEP

Liked the approach?

We apply the same principles to client projects: AI, automation, products that don't die after launch.