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
You could round to n digits precision with:
double round( double x ) { const double sd = 1000; //for accuracy to 3 decimal places return int(x*sd + (x<0? -0.5 : 0.5))/sd; }