Could someone tell me why ceil() isn't working?

I've got this function

double round (double n)
{
n = n * 10;
ceil(n);
n = n / 10;
return n;
}

It's working except for the ceil(n); part. When I step through it, ceil() does nothing to n. For example, if I pass 12.04195 to it, the first line makes n = 120.4195, ceil() does nothing, and the third line makes n = 12.04159 again. I have #include <cmath> in the header, and pow() is working fine.

Thanks.
Last edited on
http://www.cplusplus.com/reference/clibrary/cmath/ceil/

Google is your friend. Basically you need to either use the return value, or save it because that's the result you need.
Seriously webJose, I've been on that page. You think I'd come bother you without having hit the cmath reference and Google?? ;-)

I'm in the Beginners section for a good reason. I was confused about how ceil works. I was thinking it used the variable you pass it as a reference for some reason. But like you said, it returns a value and you need to stick it somewhere. Thanks.

Here's what I have now:

double round (double n)
{
n = n * 10000;
n = ceil(n + .00005);
n = n / 10000;
return n;
}

My intention is to round a number to 4 decimal places.
Last edited on
Topic archived. No new replies allowed.