DEV Community

Geek Lady
Geek Lady

Posted on

Questions about float-point numbers

I roughly know how float point system works. But I don't know why the second looks normal?

If I run

console.log(1.01+2.05);
console.log(1.01+2.05+4.21);
Enter fullscreen mode Exit fullscreen mode

I'll get

3.0599999999999996
7.27
Enter fullscreen mode Exit fullscreen mode

Also, I see some people multiply the number by 100 and add them up, finally divide it by 100. Doesn't this solution have any problem? What if the number is really big? There's overflow concern, isn't it?

Top comments (0)