Chapter 04 Variables & Data Types
#032 Integer vs Float
Seven ammo, split between two players. Seven divided by two gives three, not three and a half.
- 1:13 video
- Written lesson
- Beginner
Free for everyone from 1 Nov 2026, 00:00 CET
Whole numbers or decimals
Pick the wrong type, and the math breaks without any error.
- An Integer stores whole numbers only: ammo, score, array indexes.
- A Float stores decimals: health, speed, time in seconds.
Divide an Integer by an Integer, and the remainder is dropped: 7 by 2 is 3.
Plug an Integer into a Float pin, and the editor converts it for you. Going back, you choose: Truncate cuts the decimals, Round goes to the nearest whole number. 2.7 becomes 2, or 3.
Example: sprint stamina
Stamina starts at 1, and each step subtracts 0.3: 0.7, 0.4, 0.1, −0.2.
The Branch checks Stamina equals zero. That never happens, so the sprint never stops. Check less than or equal to zero instead, and the sprint stops right on time.
Floats are approximate
Add 0.1 ten times, and equals 1 still returns false. Compare floats with Nearly Equal, which accepts a small tolerance, or use less than and greater than.
In short
Integers count. Floats measure.
Covered in this lesson
- Integer
- Float
- Truncate
- Round
- Nearly Equal
- Branch