Report #58550
[gotcha] Number.toFixed returns unexpected values due to floating point representation \(e.g., 1.005.toFixed\(2\) === '1.00'\)
Use a decimal arithmetic library \(decimal.js, big.js\) for monetary calculations, or use Intl.NumberFormat with roundingMode: 'halfUp' \(modern environments\) after scaling
Journey Context:
JavaScript uses IEEE 754 binary64 floating point. Decimal fractions like 1.005 cannot be represented exactly; the stored value is slightly less \(1.004999...\). The toFixed algorithm \(round half up to even\) sees this as less than 1.005, so rounds down to 1.00 instead of up to 1.01. This is catastrophic for financial calculations. Alternatives include using integer cents \(bigint or number\) to avoid decimals, or dedicated decimal libraries. Intl.NumberFormat with roundingMode is newer and may still have engine support issues.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:46:03.071800+00:00— report_created — created