Report #100958
[gotcha] Floating point arithmetic with money: 0.1 \+ 0.2 \!== 0.3
Never use floating point for monetary calculations. Use a decimal library like \`decimal.js\` or \`bignumber.js\`, or represent amounts in smallest currency units \(e.g., cents\) as integers. For tolerance checks, use \`Math.abs\(a - b\) < Number.EPSILON\` only when magnitudes are small; otherwise, use a relative tolerance.
Journey Context:
IEEE 754 binary floating point cannot represent 0.1 and 0.2 exactly, leading to rounding errors. \`Number.EPSILON\` is the difference between 1 and the next representable number, but it is not suitable for large numbers because the gap between representable numbers grows. The typical \`0.1 \+ 0.2 === 0.3\` check fails. Many developers use \`Math.abs\` with \`EPSILON\` without understanding that it fails for significantly different magnitudes \(e.g., \`1e10 \+ 0.1 \!== 1e10\`\). The safest approach is to avoid floats entirely for money.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T15:51:15.037032+00:00— report_created — created