Why 0.1 + 0.2 Doesn't Equal 0.3 (And Why That's Actually Fine)

Picture this: You’re debugging what should be a simple calculation in your JavaScript code, and you stumble upon something that makes you question everything you thought you knew about math. You open up your browser’s console and type: console.log(0.1 + 0.2); // Output: 0.30000000000000004 Wait, what? Did my computer just fail elementary school math? Before you start shopping for a new laptop or questioning the fundamental laws of the universe, let me assure you: your computer is fine, and so is math. Welcome to the wonderfully weird world of floating-point arithmetic! ...

May 19, 2024 · 5 min · me