Skip to content

Python double precision

  • by

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.

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.

Python double precision example

Simple example code double length binary representation of variable compared to the binary representation of float.

from decimal import Decimal
d = Decimal(2.675)

print(d)
print(type(d))

print(float(d))
print(type(float(d)))

Output:

Python double precision

Comment if you have any doubts or suggestions on this Python precision topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading