🧩Floating-Point Number
Also known as Float, Decimal Number, Double
A number with a decimal part, like 3.5. It can be off by a hair.
Think of it like
Think of it like a ruler with very fine marks. It is close for nearly any length, but not always spot on.
Example
A fitness app stores a 5.2 km run as a float. For the price of the plan it uses 999 cents, not 9.99.
Why it matters
Distances, weights and scores often have decimals. Knowing the tiny error keeps you from using floats for money.
Definition
Example code
python
>>> 0.1 + 0.2
0.30000000000000004Common mistake
Key takeaways
- 1Has a decimal part. Holds values like 3.5 and 0.25.
- 2Close, not exact. Most values are a very near guess.
- 3Not for money. Use whole cents or a decimal type.