Skip to content

Python float vs double

  • by

We can’t compare float vs double in Python because Python does not have C-style float, it only has a C-style double, which is called float.

Other programming languages float has 7 decimal digits of precision and occupy 32 bits. A double has 15 decimal digits of precision and occupies a total of 64 bits.

Python float vs double example

Simple example code you can convert an int to a float.

n1 = 45
n2 = 3.14159265359

f = float(n1)
print(f)
print(type(f))

i = int(n2)
print(i)
print(type(i))

Output:

Python float vs double

What is the Python equivalent of C types float, double and long?

Answer: In C, a double is just a double-precision float (meaning smaller numbers are represented more accurately). In Python, it’s just a float. Similarly, a long is (was) just a int that stored larger numbers.

Comment if you have any doubts or suggestions on this Python comparison 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