+ 1
Round in c++
How do I round fractions to integers in c++? If you can use a round() what is the syntax?
3 Respostas
+ 1
double x = 11.16, result;
result = round(x);
cout << "round(" << x << ") = " << result << endl;
Please follow the link👇👇
https://www.geeksforgeeks.org/round-in-cpp/
+ 1
ceil(5.3); //output is 6.0
round(5.3); //5.0
floor(5.3); //5.0
Before include math header.
Edit: for example see this...
http://www.cplusplus.com/reference/cmath/round/
+ 1
You can use type conversion after what the others suggested to get an integer type value.
float a = 45.6;
int x = (int) round(a);
// You will get x as 46.
// You will get x as 46.0 if not type converted which cannot be stored in a int type variable.