round - C math.h

C examples for math.h:round

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns the integral value that is nearest to x.

Prototype

long double roundl (long double x);
long double round (long double x);
     double round  (double x);
      float roundf (float x);
      float round (float x);
     double round (T x);           

Parameters

Parameter Description
x Value to round.

Return Value

The value of x rounded to the nearest integral as a floating-point value.

Demo Code


#include <stdio.h>
#include <math.h> /* round, floor, ceil, trunc */

int main ()/*from  w w w . j  a v a 2  s.  c o m*/
{

  printf ("%f\n",round( 2.3));
  printf ("%f\n",round( 2.8));
  printf ("%f\n",round( 2.5));
  printf ("%f\n",round( 2.4));
  printf ("%f\n",round( 2.9));


  printf ("%f\n",round( -2.3));
  printf ("%f\n",round( -2.8));
  printf ("%f\n",round( -2.5));
  printf ("%f\n",round( -2.4));
  printf ("%f\n",round( -2.9));
            
  return 0;
}

Related Tutorials