Float (Python)

A float in Python is a number with a decimal point, such as 3.14 or -0.5. It represents real numbers and is stored as a 64-bit floating-point value.

Python

Because floats are stored in binary, some decimals can't be represented exactly, which can cause tiny rounding errors (for example 0.1 + 0.2 is not exactly 0.3). Use round() or the decimal module when precision matters.

Examples

Python

price = 19.99
print(price + 0.01)
print(0.1 + 0.2)

Output:

20.0
0.30000000000000004

Learn it in a lesson

See also

Back to the Dictionary