llrint Function

Returns the argument rounded to the nearest integer value.

Include

<math.h>

Prototype

long long int llrint(double x);

Argument

x
the value to round

Return Value

Returns the value of x rounded to the nearest integer value using the current rounding direction. The rounded integer is returned as an integer value.

Remarks

The value returned is unspecified if the rounded value is outside the range of the return type. A range error may occur if the magnitude of x is too large.

Example

#include <math.h>
#include <stdio.h>

int main(void)
{
  double x;
  long long int y;

  x = 10.103;
  y = llrint(x);
  printf("The nearest integer value to %f is %lld\n", x, y);

  x = 10.51;
  y = llrint(x);
  printf("The nearest integer value to %f is %lld\n", x, y);
}

Example Output

The nearest integer value to 10.103000 is 10
The nearest integer value to 10.510000 is 11