C Math lround() Function
Example
Round numbers to the nearest long integer:
printf("%ld\n", lround(6.4));
printf("%ld\n", lround(6.5));
printf("%ld", 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 <math.h> header file.
Tip: round() rounds in the same way, but returns a double.
Syntax
long lround(double x);
There are also versions for float and long double values: lroundf() and lroundl().
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 C Math Tutorial.