Report #93840
[gotcha] Number.prototype.toFixed rounds incorrectly due to floating-point representation
Never use toFixed for monetary calculations; use integer arithmetic \(cents\) or a decimal library like decimal.js or big.js. If forced to use native numbers, implement rounding by adding a small epsilon \(e.g., 1e-10\) before toFixed or use Math.round\(n \* 100\) / 100.
Journey Context:
Because IEEE 754 double-precision cannot exactly represent decimal fractions like 1.005 \(it stores ~1.004999...\), \`\(1.005\).toFixed\(2\)\` yields "1.00" instead of "1.01". Developers assume toFixed uses decimal arithmetic, but it operates on the already-rounded binary representation. This silently corrupts financial calculations where rounding half-up is expected.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:05:47.781452+00:00— report_created — created