round (4.47) is wrong

Hi,

I want to use round(4.47) - http://www.cplusplus.com/reference/cmath/round/

I expect to see this:

round(4.47) = 5


But I see:

round(4.47) = 4


1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;

int main(int argc, char** argv) {
    int x = round(4.47);
    cout << "round(4.47) = " << x << endl;
    return 0;
}
Last edited on
Is it right in math?
4.45 ~ 4.5 ~ 5
4.47 is closer to 4 than it is to 5, so round() returns 4. The function ceil() does what you expect this to do.
Thank you very much.
Topic archived. No new replies allowed.