Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 大浮点除法_Python_Floating Point - Fatal编程技术网

Python 大浮点除法

Python 大浮点除法,python,floating-point,Python,Floating Point,我尝试在Python中使用浮点数进行除法,但即使我尝试将浮点数四舍五入,也得到了不正确的结果,但不起作用。python是如何对大浮点数进行除法的 >>> div = 1.45751734864e+15/30933 >>> print div 47118525478.9 在java中也是如此 >>> double div = 1.45751734864e+15/30933; >>> System.out.println(di

我尝试在Python中使用浮点数进行除法,但即使我尝试将浮点数四舍五入,也得到了不正确的结果,但不起作用。python是如何对大浮点数进行除法的

>>> div = 1.45751734864e+15/30933
>>> print div
47118525478.9
在java中也是如此

>>> double div = 1.45751734864e+15/30933;
>>> System.out.println(div);
4.711852547893835E10

Python和Java返回的数字相同:

使用python 2.7.3的IPython:

In [1]: 1.45751734864e+15/30933
Out[1]: 47118525478.93835

In [2]: 1.45751734864e+15/30933.0
Out[2]: 47118525478.93835

In [3]: 1.45751734864e+15/30933.0-4.711852547893835E10
Out[3]: 0.0
Python 3.3:

Python 3.3.0 (default, Mar 22 2013, 20:14:41) 
[GCC 4.2.1 Compatible FreeBSD Clang 3.1 ((branches/release_31 156863))] on freebsd9
Type "help", "copyright", "credits" or "license" for more information.
>>> 1.45751734864e+15/30933
47118525478.93835
>>> 1.45751734864e+15/30933-4.711852547893835E10
0.0
>>> 

您可以使用十进制模块来提高精度


阅读:并且

Python和Java结果都是正确的:

Python

47118525478.9
Java

4.711852547893835E10
但是在Java中,数字是按格式打印的。因此,它相当于:

4.711852547893835*10^10=47118525478.9835

如果您想以指数表示法格式打印Python的输出,请使用:


在我的32位系统中,我得到:
47118525478.93835
在python中,这个数字怎么不正确?Python默认为您显示固定数量的数字,以使值更具可读性,但这并不意味着值本身不更精确。@jamylak:较旧的Python版本只使用
repr()
输出中最重要的12位数字。“结果不正确”是什么意思?4点和47118525478点是什么意思什么意思?
4.711852547893835E10
>>> div = 1.45751734864e+15/30933
>>> print '{:e}'.format(float(div))
4.711853e+10