In C, llround() rounds a double to the nearest integer value and returns it as a long long. Halfway cases move away from zero, so llround(1.5) is 2 and llround(-1.5) is -2.
You pass one double. The result is a long long. Include <math.h>. On GCC, link with -lm. Use lround() when a long is enough.
The halfway rule does not depend on the current floating-point rounding mode. That makes llround() predictable for money-style rounding when you always want .5 to move outward.
Syntax
Pass the floating-point number. Start with this call.
C
llround(1.5);
Call
What it does
llround(1.5)
Rounds halfway away from zero and returns 2 as a long long.
Include <math.h>. On GCC, link with -lm. Print the result with %lld.
Library declarations
C
long long llround(double x);
long long llroundf(float x);
long long llroundl(long double x);
Parameters
Parameter
Description
x
Required. The double to round to the nearest integer value.
Return Value
Return Value
Description
long long
The rounded integer. Halfway values move away from zero.
C Examples
Example 1 — Basic Rounding
Round positive and negative values, including a halfway case.