In C, lrint() rounds a double to the nearest integer using the current rounding mode, then returns that value as a long. The default mode is usually round-to-nearest, ties to even.
You pass one double. The result is a long. Include <math.h>. On GCC, link with -lm. For a wider integer result, use llrint().
lrint() is the long twin of llrint(). Unlike lround(), it does not hard-code a half-away-from-zero rule.
Syntax
Pass the floating-point number. Start with this call.
C
lrint(2.5);
Call
What it does
lrint(2.5)
Rounds with the current mode; often 2 under default ties-to-even.
Include <math.h>. On GCC, link with -lm. Print with %ld on most systems.
Library declarations
C
long lrint(double x);
long lrintf(float x);
long lrintl(long double x);
Parameters
Parameter
Description
x
Required. The double to round according to the current rounding mode.