Is there any way to round numbers in C?
I do not want to use ceil and floor. Is there any other alternative?
I came across this code snippet when I Googled f
I'm not sure that's such a good idea. That code depends on casts, and I'm fairly sure that the exact truncation is undefined.
float result = (num - floor(num) > 0.5) ? ceil(num) : floor(num);
I'd say that this is a much better way (which is basically what Shiroko posted) since it doesn't depend on any casts.