round number in c?
Hi!
Is there a function which rounds numbers in c?
If not, how would you do it??
- pi256
casting a float or double to an int truncates, ceil(f) returns the smallest int not less than f (as a double) floor(f) returns the largest int not greater than f (again as a double)
inline int round(double x) {return (int)(x+0.5);}
rounds up.
inline int round(double x) {return (int)(x+0.5);}
rounds up.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement