C examples for math.h:round
function
<cmath> <ctgmath> <math.h>
Returns the integral value that is nearest to x.
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);
Parameter | Description |
---|---|
x | Value to round. |
The value of x rounded to the nearest integral as a floating-point value.
#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; }