Glossary

Float

Also known as: floating-point number, double

The float type in Python represents real (or more precisely, rational approximations of real) numbers using IEEE 754 double-precision binary floating-point format. This gives roughly 15–17 significant decimal digits of precision and a range from about 5 × 10⁻³²⁴ to 1.8 × 10³⁰⁸. Floats are created with a decimal point (3.14), scientific notation (6.022e23), or by calling float().

The most important thing to understand about floats is that they cannot represent most decimal fractions exactly. The expression 0.1 + 0.2 evaluates to 0.30000000000000004, not 0.3, because 0.1 has no exact binary representation. This is not a Python bug — it affects every language using IEEE 754. For financial calculations or other contexts requiring exact decimal arithmetic, use the decimal.Decimal type from the standard library.

Floats support all arithmetic operations, including true division (/), which always returns a float even when both operands are integers. Special float values include float('inf'), float('-inf'), and float('nan') (not a number). Floats are immutable, like integers: every arithmetic operation produces a new float object. The math module provides mathematical functions — sqrt, log, sin, cos, and many others — that operate on floats.

Related terms: Integer, Immutable

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.