Casting a Variable
Sometimes, you can use a variable in multiple ways:
Float as an integer
Integer as a float
""can befalseor0This is called an empty string
Other times, the variable has to be cast into another type using an extra step.
This varies widely among languages, so it's best to look it up.
Examples:
Processing example:
float amount = 1.0;
int amountAsInt = int(amount);
// now amountAsInt can be used where an integer is neededC# example:
int count = 3;
string countAsString = count.ToString();
// now countAsString can be used where a string is neededPython example:
count = 3
countAsFloat = float(count)
# now countAsFloat can be used where a float is neededLast updated
Was this helpful?