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
A certain type of rounding is also implemented in Boost:
#include
#include
template T round2(const S& x) {
typedef boost::numeric::conversion_traits Traits;
typedef boost::numeric::def_overflow_handler OverflowHandler;
typedef boost::numeric::RoundEven Rounder;
typedef boost::numeric::converter Converter;
return Converter::convert(x);
}
int main() {
std::cout << round2(0.1) << ' ' << round2(-0.1) << ' ' << round2(-0.9) << std::endl;
}
Note that this works only if you do a to-integer conversion.