How to Round a Double to an int in C++? Last Updated : 23 May, 2024 Comments Improve Suggest changes Like Article Like Report In C++, the double data type is used to store floating-point numbers with double precision. In this article, we will learn how to round a double value to an int in C++. Example: Input: double val= 2.6 Output: Integer for double value 2.5 is: 3 Rounding a Double to an Int in C++To round a double value to a nearest integer value we can use the std::round() function from the <cmath> library , we have to pass a double value as a parameter to this function and it computes the nearest integer value for it. Syntax of std::round()int intValueName = round(doubleValue);C++ Program to Round a Double to an intThe following program demonstrates how to round a double value to an int in C++. C++ // C++ program to demonstrates how to round a double value // to an int #include <cmath> #include <iostream> using namespace std; int main() { // Define double values double doubleValue1 = 2.5; double doubleValue2 = 9.99; // rounding the double values to int type int intValue1 = round(doubleValue1); cout << "The integer for double value " << doubleValue1 << " is " << intValue1 << endl; int intValue2 = round(doubleValue2); cout << "The integer for double value " << doubleValue2 << " is " << intValue2 << endl; return 0; } OutputThe integer for double value 2.5 is 3 The integer for double value 9.99 is 10 Time Complexity: O(1)Auxilliary Space: O(1) Comment More infoAdvertise with us Next Article How to Round a Double to an int in C++? H heysaiyad Follow Improve Article Tags : C++ Programs C++ CPP Examples Practice Tags : CPP Similar Reads How to Convert wstring to double in C++ In C++, std::wstring is a type of string where each character is of a wide character type. Converting wstring to a double in C++ can be a common requirement especially when dealing with the inputs that are stored as unicode characters. In this article, we will learn how to convert a wstring to a dou 2 min read How to Convert Float to int in C++? In C++, the float is a short term for floating point value that is used to define numeric values with decimal points. The floating point numbers can be converted to integers using the process called type casting. In this article, we will learn how to convert a float value to an int in C++. Example: 2 min read How Do I Print a Double Value with Full Precision Using cout? The double value in C++ has a precision of up to 15 digits but while printing it using cout, it only prints six significant digits. In this article, we will learn how to print the double value with full precision. For Example, Input: double var = 12.3456789101112 Output: var = 12.3456789101112Print 2 min read C++ String to Float/Double and Vice-Versa In this article, we will learn how to convert String To Float/Double And Vice-Versa. In order to do conversion we will be using the following C++ functions: std::stof() - convert string to floatstd::stod() - convert string to doublestd::atof() - convert a char array to doublestd::to_string - convert 3 min read Generate Random Double Numbers in C++ Double is a data type just like a float but double has 2x more precision than float. One bit for the sign, 11 bits for the exponent and 52* bits for the value constitute the 64-bit IEEE 754 double precision Floating Point Number known as "double." Double has 15 decimal digits of precision. In this a 2 min read Like