lround - C math.h

C examples for math.h:lround

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns the integer value that is nearest in value to x, with half way cases rounded away from zero.

The rounded value is returned as a value of type long int.

Prototype

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

Parameters

Parameter Description
x Value to round.

Return Value

The value of x rounded to the nearest integral, casted to a value of type long int.

Example

Demo Code


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

int main ()//from w w  w.j a  v  a  2  s  .c o m
{
  printf ( "%ld\n", lround(2.1) );
  printf ( "%ld\n", lround(3.9) );
  printf ( "%ld\n", lround(-2.1) );
  printf ( "%ld\n", lround(-3.0) );
  return 0;
}

Related Tutorials