herrdu / notes

0 stars 0 forks source link

0.1 + 0.2 returns 0.30000000000000004 #76

Open herrdu opened 3 years ago

herrdu commented 3 years ago

因为是 js 中浮点数是使用 IEEE 754 双精度64位浮点数(需翻墙)来存储的。所以,在 js 中

0.1 的存储

二进制
0.0001100110011001100110011001100110011001100110011001101

或者 数字表示
0.1000000000000000055511151231257827021181583404541015625
0.2 的存储

0.200000000000000011102230246251565404236316680908203125

https://qntm.org/notpointthree