Advertisement

round number in c?

Started by May 27, 2001 10:20 AM
1 comment, last by pi256 23 years, 8 months ago
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.

Advertisement
Thx, really simple
Maybe next time I think twice and then ask a question

- pi256

This topic is closed to new replies.

Advertisement