我正在 PyCharm 中编写一些代码,我希望除法比目前更准确(40-50 个数字,而不是大约 15 个)。我怎样才能做到这一点?
谢谢。
最佳答案
查看 decimal
模块:
>>> from decimal import *
>>> getcontext().prec = 50
>>> Decimal(1)/Decimal(7)
Decimal('0.14285714285714285714285714285714285714285714285714')
如果您对比decimal
提供的更复杂的操作感兴趣,您还可以查看像bigfloat
这样的库。 , 或 mpmath
(我使用,并且非常喜欢。)
关于python - 提高 float 除法的准确性(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24112891/