Report #77831
[gotcha] JavaScript floating point arithmetic causes precision errors in financial calculations
Use integers for currency \(cents/smallest unit\) or libraries like dinero.js, currency.js, or decimal.js for arbitrary precision
Journey Context:
JS uses IEEE 754 double-precision floats. Decimal fractions like 0.1 are repeating binary fractions, causing rounding errors. For money, never use floats. The integer approach \(store $1.00 as 100 cents\) is fastest and native. Libraries like decimal.js use BigInt or string math for arbitrary precision but add overhead. Common wrong fix: toFixed\(2\) which returns string and doesn't fix comparison issues \(0.1\+0.2 === 0.3 is still false\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:14:21.513404+00:00— report_created — created