質問

How can I print more than about 10 digits of a float in python? Right now, when do

print sqr_newton(10, 3, 0.001) (where sqr_newton is newton's algorithm for square roots; returns a float)

it only gives so many digits after the decimal place... how can I get more?

役に立ちましたか?

解決

That is the standard precision for floats in python.

For arbitrary precision, you can use the bigfloat package.

他のヒント

I'm not sure what operating system you are using but bigfloat requires that the MPFR and GMP libraries already exist on your computer. It may not be easy to use on Windows.

There are two other multiple precision libraries available that support Windows:

1) mpmath which is written in pure Python and is stable and well documented.

2) gmpy2 which is currently under active development. The next release should have a stable API. (Famous last words...)

If bigfloat works for you, great! It is a well-designed and documented package.

Disclaimer: I maintain gmpy2 and have helped with mpmath.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top