IEEE 754: Why 0.1 + 0.2 != 0.3 in JavaScript

Most JavaScript developers have seen this but never understood why. Type 0.1 + 0.2 in your console. You expect 0.3. You get 0.30000000000000004. This is not a JavaScript bug. It is IEEE 754 — the standard for how ALL computers store numbers in binary. 0.1 and 0.2 cannot be represented exactly in binary, just like 1/3 cannot be represented exactly in decimal. The tiny rounding errors accumulate. This silently breaks: → Currency calculations → Percentage comparisons → Any equality check with decimals The fix: → Use .toFixed() for display → Store currency as integers (cents) Were you aware of this? 1️⃣ Yes / 2️⃣ No #JavaScript #WebDev #Coding #SoftwareEngineering #Frontend

  • No alternative text description for this image

Developers new to this often find it shocking, but it underscores why we must treat numerical precision with extreme caution across the entire stack

To view or add a comment, sign in

Explore content categories