I was asking about round a number half up earlier today and got great help from @alk. In that post, my thinking was to round up 4.5 to 5 but round 4.4 down to 4. And the solution given by @alk was:
int round_number(float x)
{
return x + 0.5;
}
and it works very elegantly!
In this post, I would like to discuss how to implement the ceil()
function in C.
Along the same line as the last solution given by @alk, I came up with the following:
int round_up(float y)
{
return y + 0.99999999;
}
This works for all situations except when the the float number y has .00000001. I am wondering if there's any better way to do the same thing as ceil()
in C.