I need a simple floating point rounding function, thus:
double round(double);
round(0.1) = 0
round(-0.1) = 0
round(-0.9) = -1
I can find ceil()
and floor()
in the math.h - but not round()
.
Is it present in the standard C++ library under another name, or is it missing??
A certain type of rounding is also implemented in Boost:
Note that this works only if you do a to-integer conversion.
You could round to n digits precision with: