๐—ง๐—ต๐—ฒ ๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ ๐—•๐˜‚๐—ด ๐—ช๐—ถ๐˜๐—ต ๐—ก๐—ผ ๐—™๐—ถ๐˜…

Many JS developers face a weird math problem.

You type 0.1 + 0.2. You expect 0.3. JS gives you 0.30000000000000004.

JS uses the IEEE 754 standard. Binary does not store these decimals perfectly. JS does its best. The result is often slightly off.

This is dangerous for money.

Users do not want a total of 19.999999999997 dollars.

Avoid direct decimal math for money. Use cents. 1999 cents is better than 19.99. Use a decimal library for high precision.

AI agents write code. They write functions and APIs. AI agents often use floating-point math for payments. Review those pull requests. Trust the agent. Verify the decimals.

Source: https://dev.to/marrouchi/the-javascript-bug-that-will-never-get-fixed-3618