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);
I'll get
3.0599999999999996
7.27
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)