小编bat*_*n47的帖子

Python舍入错误

我只是使用python作为计算,我看到了这一点

Python 2.7.3 (default, Aug  1 2012, 05:14:39) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 62 * 41.2 * 2 / 250
20.435200000000002
>>> 62 * 4.12 * 2 / 25
20.4352
>>>
Run Code Online (Sandbox Code Playgroud)

只是为了确保我通过gcc解雇了以下代码,但这并未向我显示上述行为.我知道这可能是四舍五入的事情,但应该是统一的.为什么python在数学上加起来跟踪00000000002它不应该在那里.

C/C++代码

#include <stdio.h>
int main () {
  printf ("%lf %lf \n", 62 * 41.2 * 2 / 250, 62 * 4.12 * 2 / 25);
}
Run Code Online (Sandbox Code Playgroud)

结果是

20.435200 20.435200

如果有人对特定数字感到好奇,他们属于一些引擎位移计算比较:)

python python-2.7

3
推荐指数
1
解决办法
5241
查看次数

标签 统计

python ×1

python-2.7 ×1