What's the deal with floats? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 2

What's the deal with floats?

Just started python and I'm a little confused as to why floats are a thing. How are they different from just normal numbers and what effects do they have on the code?

1st Jan 2020, 9:33 AM
Nolen
2 Réponses
+ 11
Although in our everyday understanding we normally don't care a lot about the difference, a computer has to, because the numbers are stored and calculated differently. Python makes it relatively easy for you to use them, because whenever a float *might* occur (like when you make a division) it converts the type automatically. The biggest issue with floats are, that computers can't calculate them precisely - they are often off by a little bit, and if you do a lot of calculations with them, that can quickly add up and lead to problems. So whenever precision matters, you usually look for some workaround where you make do only with integers. It is a frequently occurring question, so use our search function here and you will find more information.
1st Jan 2020, 9:41 AM
HonFu
HonFu - avatar
+ 9
The two well-known numeric type in Python is `int` which represents a whole number, and `float` which represents a floating point number or fractal number, obviously `float` has support for decimal points while `int` doesn't. What effects they have? IIRC a math operation involving a float number operand usually yields also a float.
1st Jan 2020, 9:41 AM
Ipang