Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
and
div
eof
not
or
xor
Expand Minimize

round, roundf, roundl

Rounds a floating-point value to the nearest integer.

double round( 
   double x 
);
float round(
   float x
);  // C++ only
long double round(
   long double x
);  // C++ only
float roundf(
   float x
);
long double roundl(
   long double x
);

x

The floating-point value to round.

The round functions return a floating-point value that represents the nearest integer to x. Halfway values are rounded away from zero, regardless of the setting of the floating-point rounding mode. There is no error return.

Input

SEH Exception

Matherr Exception

± QNAN,IND

none

_DOMAIN

Because C++ allows overloading, you can call overloads of round that take and return float and long double values. In a C program, round always takes and returns a double.

Routine

Required header

round, roundf, roundl

<math.h>

For additional compatibility information, see Compatibility.

// crt_round.c
// Build with: cl /W3 /Tc crt_round.c
// This example displays the rounded results of
// the floating-point values 2.499999, -2.499999, 
// 2.8, -2.8, 2.5 and -2.5.

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

int main( void )
{
   double x = 2.499999;
   float y = 2.8f;
   long double z = 2.5;

   printf("round(%f) is %.0f\n", x, round(x));
   printf("round(%f) is %.0f\n", -x, round(-x));
   printf("roundf(%f) is %.0f\n", y, roundf(y));
   printf("roundf(%f) is %.0f\n", -y, roundf(-y));
   printf("roundl(%Lf) is %.0Lf\n", z, roundl(z));
   printf("roundl(%Lf) is %.0Lf\n", -z, roundl(-z));
}
round(2.499999) is 2
round(-2.499999) is -2
roundf(2.800000) is 3
roundf(-2.800000) is -3
roundl(2.500000) is 3
roundl(-2.500000) is -3
Show:
© 2015 Microsoft