Floating Point or Float
Description
Number with a decimal point
Used for precision
Used for percentages, but between 0 and 1 (0 and 100%)
Used for time
Examples:
Processing:
JavaScript:
Python:
Some languages have multiple types with decimal points
Example: a float in C# or Unity will need an F
after the number in the code to tell it is a float and not something else. See the example below.
^ This is one of the more common errors - forgetting that F.
Do not use commas in your numbers!
Shortcuts (Assignment Operators)
Quick Math
+=
means “add this”
-=
means “subtract this”
*=
means “multiply it by this”
/=
means “divide it by this”
This updates the variable when used.
Example:
Processing, Java-based, and C-based:
Python:
Last updated