Why a small rounding error matters
Try this in your browser console or Node.js:
console . log ( 0.1 + 0.2 ); // 0.30000000000000004
Enter fullscreen mode
Exit fullscreen mode
This is expected behavior, not a JavaScript bug. The Number type uses IEEE 754 binary floating-point values, so many decimal fractions cannot be represented exactly.
That usually isn't a problem when you're positioning an element on a page. It becomes a problem when a value represents a cryptocurrency balance, transfer amount, fee, or transaction limit.
For financial amounts, the goal is not to hide floating-point artifacts with formatting. It's to avoid introducing them into the calculation.
Let's build a small JavaScript utility that parses decimal amounts into integer base units, performs exact arithmetic, and formats the results without converting back to Number .
The code below is a standalone educational example, not a description of any particular exchange's production implementation.…