Excel和Python之间的计算结果不同

Zer*_*erk 3 excel-formula python-2.7

我是Python的新手,所以我可能会遗漏一些细微差别,但我无法理解为什么以下计算导致不同的值:

n: 0.00167322032899
Run Code Online (Sandbox Code Playgroud)

高强

(15 / 8) * n ^ 2
5.24937425502263E-06
Run Code Online (Sandbox Code Playgroud)

蟒蛇

(15/8) * n ** 2
2.79966626935e-06
Run Code Online (Sandbox Code Playgroud)

我已尝试使用括号使用复制Python的Excel结果,但无济于事.任何指导?

Ign*_*ams 9

Python 2.x中的除法默认为整数除法.

>>> (15. / 8) * 0.00167322032899 ** 2
5.2493742550226314e-06
>>> from __future__ import division
>>> (15 / 8) * 0.00167322032899 ** 2
5.2493742550226314e-06
Run Code Online (Sandbox Code Playgroud)