lroundl Function

Returns the argument rounded to an integer value.

Include

<math.h>

Prototype

long int lroundl(long double x);

Argument

x
the value to round

Return Value

Returns the value of x rounded to the nearest integer value, always rounding midway cases away from zero. The rounded integer is returned as an integer value.

Remarks

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

Example

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

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

  x = 10.103;
  y = lroundl(x);
  printf("The nearest integer value to %Lf is %ld\n", x, y);

  x = 10.5;
  y = lroundl(x);
  printf("The nearest integer value to %Lf is %ld\n", x, y);
}

Example Output

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