C Standard Library

C <math.h> - lround() Function

The C <math.h> lround() function rounds the specified number to a nearest integral value, rounding halfway cases away from zero, regardless of the current rounding mode and returns it as long int type.

The llround() function is similar to this function, except it returns the result as long long int type.


long int lround  (double x);
long int lroundf (float x);
long int lroundl (long double x);                 


x Specify a value to round.

Return Value

Returns the value of x which is first rounded to nearby integral value then casted to long int type.


In the example below, lround() function is used to round the given number.

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

int main (){

  printf("lround(10.2): %ld\n", lround(10.2));
  printf("lround(10.8): %ld\n", lround(10.8));
  printf("lround(-5.2): %ld\n", lround(-5.2));
  printf("lround(-5.8): %ld\n", lround(-5.8));
  return 0;

The output of the above code will be:

lround(10.2): 10
lround(10.8): 11
lround(-5.2): -5
lround(-5.8): -6

❮ C <math.h> Library