How to round off Float values?
The function lroundf()
will do it:
float a=20.49;
int myInt = lroundf(a);
In addition to the other answers:
float theFloat = 1.23456;
int rounded = roundf(theFloat); NSLog(@"%d",rounded);
int roundedUp = ceil(theFloat); NSLog(@"%d",roundedUp);
int roundedDown = floor(theFloat); NSLog(@"%d",roundedDown);
// Note: int can be replaced by float
For rounding to specific decimals, see the question mentioned by Alex Kazaev.