Double precision floating values in Python? Double precision floating values in Python? python python

Double precision floating values in Python?


Python's built-in float type has double precision (it's a C double in CPython, a Java double in Jython). If you need more precision, get NumPy and use its numpy.float128.


Decimal datatype

  • Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem.

If you are pressed by performance issuses, have a look at GMPY


For some applications you can use Fraction instead of floating-point numbers.

>>> from fractions import Fraction>>> Fraction(1, 3**54)Fraction(1, 58149737003040059690390169)

(For other applications, there's decimal, as suggested out by the other responses.)