使用round()或者roundf()
函数方法如下:
extern float roundf(float);
extern double round(double);
extern long double roundl(long double);
extern long int lroundf(float);
extern long int lround(double);
extern long int lroundl(long double);
使用方法举例:
double rpValue = round(1.2); // 1
double rpValue = round(1.5); // 2
double rpValue = round(-1.3); // -1
double rpValue = round(-1.6); // -2