Report #80576
[gotcha] IEEE 754 floating point arithmetic causes 0.1 \+ 0.2 \!== 0.3 and accumulates rounding errors in financial calculations
Use integer arithmetic \(cents instead of dollars\), BigInt for large integers, or arbitrary-precision libraries like decimal.js, big.js, or dinero.js. Never use binary floating point for monetary ledgers.
Journey Context:
JavaScript Numbers are IEEE 754 double-precision binary floating point. Decimal fractions like 0.1 have infinite binary representations \(0.0001100110011...\), causing rounding errors where 0.1 \+ 0.2 = 0.30000000000000004. While toFixed\(\) masks display, it doesn't fix comparison failures \(0.1 \+ 0.2 === 0.3 is false\) or accumulation errors in financial summations where associativity/commutativity matters. This is a fundamental hardware limitation, not a JS bug, requiring domain-specific numeric types for money.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:50:56.107523+00:00— report_created — created