我在用PyCharm写代码,想让我的除法运算比现在更精确一些,能有40到50位数字,而不是现在大约15位。请问我该怎么做呢?
谢谢。
看看这个 decimal 模块吧:
decimal
>>> from decimal import * >>> getcontext().prec = 50 >>> Decimal(1)/Decimal(7) Decimal('0.14285714285714285714285714285714285714285714285714')
如果你想进行比 decimal 提供的更复杂的操作,可以看看像 bigfloat 或者 mpmath 这样的库(我自己用这个,觉得非常好用)。
bigfloat
mpmath