C++ cmath lround() Function
Example
Round numbers to the nearest long integer:
cout << lround(6.4) << "\n";
cout << lround(6.5) << "\n";
cout << lround(-6.5);
Definition and Usage
The lround() function rounds a number to the nearest integer, and returns it as a long.
Halfway cases are rounded away from zero, so 6.5 becomes 7, and -6.5 becomes -7.
The lround function is defined in the <cmath> header file.
Tip: round() rounds in the same way, but returns a double.
Syntax
lround(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 value with the rounded number. |
|---|
Related Pages
Read more about math in our Math Tutorial.