Hide minor edits - Show changes to markup
type: any variable type (e.g. int, float, byte)
variable: any variable or constant
type: any variable type (e.g. int, float, byte)
variable: any variable or constant
When casting from a float to an int, the value is truncated not rounded. So both (int) 3.2 and (int) 3.7 are 3.
The cast operator traslates one variable type into another and forces calculations to be performed in the cast type.
The cast operator translates one variable type into another and forces calculations to be performed in the cast type.
[@int i;
[@ int i;
f = (float)i * 10
f = 3.6; i = (int) f; // now i is 3
int x; float f; f = i / 2; // f contains 0 - integer math can't hold fraction f = (float)i / 2; // f contains .5 - cast forces floating point math on right side of equation
(variableType1)variableType2
(type)variable
variableType1: any variable type
variableType2: any variable type
type: any variable type (e.g. int, float, byte)
variable: any variable or constant
f = (float)i
f = (float)i * 10
f = i / 2; // f contains 0 - integer math can't hold fraction f = (float)i / 2; f contains .5 - cast forces floating point math on right side of equation
f = i / 2; // f contains 0 - integer math can't hold fraction f = (float)i / 2; // f contains .5 - cast forces floating point math on right side of equation
f = i / 2; f = (float)i
f = i / 2; // f contains 0 - integer math can't hold fraction f = (float)i / 2; f contains .5 - cast forces floating point math on right side of equation
(variable type)variable
(variableType1)variableType2
[@int x;
[@int i;
@]
variableType1: any variable type
variableType2: any variable type
[@int x; float f;
f = i / 2; f = (float)i
int x;
[@int x;
@]
(variable type)variable
int x; float f;
f = (float)i
The cast operator traslates one variable type into another and forces calculations to be performed in the cast type.