# 为什么 JavaScript 中 0.1+0.2 不等于 0.3 ？

+关注继续查看

### 一、浮点数的二进制存储

JavaScript遵循IEEE754标准，在64位中存储一个数据的有效数字形式。

0.1->0.0001100110011...(0011无限循环)->0-01111111011-(1 .)1001100110011001100110011001100110011001100110011010(入)
0.2->0.001100110011...(0011无限循环)->0-01111111100-(1 .)1001100110011001100110011001100110011001100110011010(入)
0.3->0.01001100110011...(0011无限循环)->0-01111111101-(1 .)0011001100110011001100110011001100110011001100110011(舍)
0.4->0.01100110011...(0011无限循环)->0-01111111101-(1 .)1001100110011001100110011001100110011001100110011010(入)
0.7->0.101100110011...(0011无限循环)->0-01111111110-(1 .)0110011001100110011001100110011001100110011001100110(舍)

### 二、对阶运算

0.1+0.2->10.0110011001100110011001100110011001100110011001100111
0.3+0.4->10.1100110011001100110011001100110011001100110011001101

0.1+0.2->1.00110011001100110011001100110011001100110011001100111->1.0011001100110011001100110011001100110011001100110100(入)
0.3+0.4->1.01100110011001100110011001100110011001100110011001101->1.0110011001100110011001100110011001100110011001100110(舍)

00111->0100
01101->0110

### 四、总结思考

7322 0

3377 0

4589 0

8181 0

9495 0
windows server 2008阿里云ECS服务器安全设置

5525 0

2230 0
+关注
47

0

《SaaS模式云原生数据仓库应用场景实践》

《看见新力量：二》电子书