Report #6897
[gotcha] Decimal libraries like decimal.js lose precision when initialized with number literals instead of strings
Always pass numeric strings to the Decimal constructor: new Decimal\('0.1'\) instead of new Decimal\(0.1\). If you must convert a number, first convert it to string with .toFixed\(\) or a custom formatter that preserves value.
Journey Context:
Developers reach for decimal.js to fix 0.1 \+ 0.2 \!== 0.3, but they instinctively pass the number literal 0.1 into the constructor. By the time the Decimal constructor receives the argument, JavaScript has already rounded the literal to the nearest IEEE 754 double \(0.10000000000000000555...\), so the Decimal object is initialized with the imprecise value already baked in. The library cannot recover the intended '0.1' from the corrupted Number. The fix is to treat Decimal as a string processor, not a number wrapper. Alternatives like BigInt cannot handle decimals, and native BigDecimal is not yet standard.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:17:54.846665+00:00— report_created — created