Click to See Complete Forum and Search --> : Round in C++ ??


uNsignedINT
May 21st, 2003, 09:12 AM
Hello, I'm a rookie in C++. Is there any function that rounds a number (ex. 5.67-->6)

Thanks

Yves M
May 21st, 2003, 09:20 AM
Don't feel like a rookie, I don't know the C++ way either (or maybe I'm a rookie myself ;) )

The "C" way is to use something like the following:

#include <math.h>

long round(double val)
{
return static_cast<long>(floor(val + 0.5));
}

uNsignedINT
May 21st, 2003, 10:02 AM
Originally posted by Yves M
Don't feel like a rookie, I don't know the C++ way either (or maybe I'm a rookie myself ;) )

The "C" way is to use something like the following:

#include <math.h>

long round(double val)
{
return static_cast<long>(floor(val + 0.5));
}


Thanks for the tip!! See ya!:D