In C, llrint() rounds a double to the nearest integer value using the current rounding mode, then returns that value as a long long. The default mode is usually round-to-nearest with ties to even.
You pass one double. The result is a long long, not a floating-point type. Include <math.h>. On GCC, link with -lm. Prefer lrint() when a long is wide enough.
Unlike llround(), which uses a fixed halfway rule (away from zero), llrint() follows the floating-point environment. Changing the rounding mode with fesetround() can change the result for the same input.
Syntax
Pass the floating-point number. Start with this call.
C
llrint(2.5);
Call
What it does
llrint(2.5)
Rounds using the current mode; often 2 (ties to even) in the default mode.
Include <math.h>. On GCC, link with -lm. The result type is long long, so print it with %lld.
Library declarations
C
long long llrint(double x);
long long llrintf(float x);
long long llrintl(long double x);
Parameters
Parameter
Description
x
Required. The double to round according to the current rounding mode.
Return Value
Return Value
Description
long long
The rounded integer value. If the result is out of range, the call may raise a floating-point exception.
C Examples
Example 1 — Basic Rounding to long long
Round a few doubles with the default rounding mode (usually nearest, ties to even).