+ 1

Round in c++

How do I round fractions to integers in c++? If you can use a round() what is the syntax?

25th Jan 2020, 8:28 AM
Alisa🌸🌸
Alisa🌸🌸 - avatar
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/
25th Jan 2020, 9:00 AM
Scooby
Scooby - avatar
+ 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/
25th Jan 2020, 9:03 AM
Jayakrishna 🇮🇳
+ 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.
25th Jan 2020, 9:51 AM
Avinesh
Avinesh - avatar