hey guys, as well all know, C rounds downwards, anyway, i'm trying to write a function that would make it round upwards, and got something like this:
int
round_up(float x)
{
int y = 100*x;
double z = 100*x-y;
if(z>0)
y = (x+0.01)*100;
else
y = x*100;
return y;
}
but the thing is if i have a test case with x = 0.80, the value of z, which is
100*0.80 - 80
is not actually equal to 0, i printed out the value and it gave me something like 0.0000001. I know this is because of the limitations of the machine being 32 bits, but is there anyway to around this? I was thinking of making the if statement into
if(z > 0.00001)
or something similar, but thats really a last resort
thanks.