The cast operator translates one variable type into another and forces calculations to be performed in the cast type.
type: any variable type (e.g. int, float, byte)
variable: any variable or constant
int i; float f; f = 3.6; i = (int) f; // now i is 3
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.
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.