DEV Community

Geek Lady
Geek Lady

Posted on

1 1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay