1.round
作用:将浮点值舍入为最接近的整数
有下面几个重载函数:
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
);
例子:
void testRound()
{
double x = 2.499999;
float y = 2.8f;
long double z = 2.5;
printf("round(%f) is %.0f\n", x, round(x));