Python Lessons – 1.3 Floating numbers

Lezioni di Python - 1.3 Numeri float
Scrivi una didascalia…


Floats, or floating numbers, are decimal numbers, that is, those that have a comma (0.24, -3.1423333).

These numbers can be defined directly by writing the number with a comma, or using operators that generate decimal numbers such as divisions between integers.

Computers can store decimal numbers within a certain level of accuracy (number of limited decimal places). Therefore cumulative operations on decimal numbers could lead to ever greater approximations.

This is a very important factor that you will have to take into account in the future. Then write in a 1/3 code that 0.33333333 certainly does not express the same accuracy.

As you can already see with a single operation on the same value we already have a certain margin of approximation. There could be cases in which these values will be operated dozens and dozens of times ….

When performing a transaction between different numbers (both integers and floats), the result will be float.

Why not 14.3?

Python takes care of converting integers (integer) to float implicitly whenever they are included in mathematical operations with other float numbers.

⇐ Go to Python Lesson 1.2 – Simple operations

Go to Python Lesson 1.4 – Other numeric operations ⇒

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.