floating point - round() for float in C++ -


I need a simple floating point rounding function, as follows:

  Double round (Double) ; Round (0.1) = 0 round (-0.1) = 0 round (-0.9) = -1  

I can get the floor ceil () and Is () in math.h - but round () .

Is it present under any other name in the standard C ++ library, or is it missing ??

There is no round () in the C ++ 98 standard library. You can write one yourself:

  Double round (double D) {return floor (D +0.5); }  

There is no round function in the C ++ 98 standard library, this is possibly possible to be implemented in different ways. The above is a common method but there are other people who are less biased and usually better if you are going to score a lot; Although it is slightly more complicated to implement.


Comments