DEV Community

Cover image for How to Compare Decimals in JavaScript

How to Compare Decimals in JavaScript

Hello Dev World Blog on January 14, 2021

Today we are doing a little debugging and dealing with decimals in JavaScript. Disclaimer: There are MANY ways to solve this problem this is an a...
Collapse
 
lexlohr profile image
Alex Lohr

The problem here is that all numbers in JS are IEEE 754 64 bit numbers (1 bit sign, 11 bit exponent, 52 bit mantissa). Allowing for imprecision will solve the false negative, but will increase the chance of false positives at the same time.

A better solution would be to go beyond this number format and use something like big.js instead.