提高浮点除法的精度(python) [英] Increase Accuracy of float division (python)
本文介绍了提高浮点除法的精度(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在 PyCharm 中编写一些代码,我希望除法比现在更准确(40-50 个数字而不是大约 15 个数字).我怎样才能做到这一点?
谢谢.
解决方案
查看 decimal
模块:
如果您对比 decimal
提供的更复杂的操作感兴趣,您还可以查看诸如 bigfloat
或 mpmath
(其中我用过,很喜欢.)
I'm writing a bit of code in PyCharm, and I want the division to be much more accurate than it currently is (40-50 numbers instead of about 15). How Can I accomplish this?
Thanks.
解决方案
Check out the decimal
module:
>>> from decimal import *
>>> getcontext().prec = 50
>>> Decimal(1)/Decimal(7)
Decimal('0.14285714285714285714285714285714285714285714285714')
If you're interested in more sophisticated operations than decimal
provides, you can also look at libraries like bigfloat
, or mpmath
(which I use, and like a lot.)
这篇关于提高浮点除法的精度(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文