在python中显示许多很多小数位

时间:2015-08-13 20:21:24

标签: python decimal

我将phi逼近50位小数并想要返回我计算出的值。我不想打印它,否则我不能在计算中使用它。 我怎么能这样做因为python只想显示11位小数或类似的东西? 感谢

1 个答案:

答案 0 :(得分:0)

python浮点数没有那么精确。你需要使用python decimal:

from decimal import getcontext, Decimal
getcontext().prec = 50
print(Decimal(1) / Decimal(7))

缺点是使用这些计算所需的时间比使用浮点数的计算要多得多。