Floats
Floats are similar to integers, but they can also include decimal fractions. Float means that the numbers always have a decimal part separated by a dot. The number of decimals is also called precision, e.g.
- 5.8656345
- -332.8463463463753646
Normally you do not need very high precisions for your calculations and two or three decimals will be enough in 99% of all cases. Floats and integers can be used together and the result is always a floating number:
value1 = 5 value2 = 3.6222 result = value1 - value2 scene.message(str(result))
Â
If an instruction expects a floating number and you want to enter a value of exactly 2, for example, then you really have to type in a floating number, not an integer:
getNeighbors(2.0)
Â
Floating numbers can be translated into integers and vice versa, but there might be a problem with precision, because the decimals will be truncated, leaving only the integer part:
int(7.57634) = 7 or int(6.99999) = 6 float(3) = 3.0
Â