C++ cmath llround() Function
Example
Round numbers to the nearest long long integer:
cout << llround(2.4) << "\n";
cout << llround(2.5) << "\n";
cout << llround(-2.5);
Definition and Usage
The llround() function rounds a number to the nearest integer, and returns it as a long long (an integer type that can store very big numbers).
Halfway cases are rounded away from zero, so 2.5 becomes 3, and -2.5 becomes -3.
The llround function is defined in the <cmath> header file.
Tip: round() rounds in the same way, but returns a double.
Syntax
llround(double x)
The function also works with float and long double values.
Parameter Values
| Parameter | Description |
|---|---|
| x | Required. The number to round. |
Technical Details
| Returns: | A long long value with the rounded number. |
|---|
Related Pages
Read more about math in our Math Tutorial.