取整方法
头文件#include <math.h>?
头文件#include <math.h>?
1. 函数double ceil(double x)
向下取整
eg:
ceil(-11.5) == -11 ceil(1.5)== 1 ceil(-6.2) == -6 ceil(6.1) == 6
向下取整
eg:
ceil(-11.5) == -11 ceil(1.5)== 1 ceil(-6.2) == -6 ceil(6.1) == 6
2. 函数 floor(double x) floorf(float x) floorl(long double x)
向上取整
eg:
floor(-11.5) == -12 floor(1.5) == 2 floor(-6.2) == -7 floor(6.1) == 7
向上取整
eg:
floor(-11.5) == -12 floor(1.5) == 2 floor(-6.2) == -7 floor(6.1) == 7
3. 函数round()
四舍五入
eg:
round(-11.5) == -12 round(1.5) == 2 round(-6.2) == -6 round(6.1) == 6
四舍五入
eg:
round(-11.5) == -12 round(1.5) == 2 round(-6.2) == -6 round(6.1) == 6