34.5 => 34 round

Hi,
in matlab there are functions that round integers,
im using visual studio 2010 c++,
functions in matlab are:

ceil(34.5) // result is 35;

floor(34.5) // result is 34;

is there any thing that does such thing in c++ ?
i think you could do something like this

1
2
3
4
int round(double x) {
      x += .5;
      return x;
}
there is plenty of functions in <cmath>:
std::ceil() rounds towards +∞
std::floor() rounds towards −∞
std::trunc() rounds towards 0
Topic archived. No new replies allowed.