C++ cmath llrint() Function
Example
Round numbers to a long long integer:
cout << llrint(2.7) << "\n";
cout << llrint(2.5) << "\n";
cout << llrint(3.5);
Definition and Usage
The llrint() function rounds a number to an integer, and returns it as a long long (an integer type that can store very big numbers).
It uses the current rounding mode (a setting that decides how numbers are rounded). By default, numbers are rounded to the nearest integer, and halfway cases are rounded to the nearest even integer. So 2.5 becomes 2, and 3.5 becomes 4.
The llrint function is defined in the <cmath> header file.
Tip: Use llround() to round halfway cases away from zero, like 2.5 to 3.
Syntax
llrint(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.