In C, lround() rounds a double to the nearest integer value and returns it as a long. Halfway cases move away from zero, so lround(1.5) is 2 and lround(-1.5) is -2.
You pass one double. The result is a long. Include <math.h>. On GCC, link with -lm. For a wider result, use llround().
The halfway rule is fixed. Changing the floating-point rounding mode does not change how lround() treats .5 values.
Syntax
Pass the floating-point number. Start with this call.
C
lround(1.5);
Call
What it does
lround(1.5)
Rounds halfway away from zero and returns 2 as a long.
Include <math.h>. On GCC, link with -lm. Print with %ld on most systems.
Library declarations
C
long lround(double x);
long lroundf(float x);
long lroundl(long double x);
Parameters
Parameter
Description
x
Required. The double to round to the nearest integer value.
Return Value
Return Value
Description
long
The rounded integer as a long. Halfway values move away from zero.
C Examples
Example 1 — Basic Rounding
Round positive and negative values, including halfway cases.