floor、ceil、round、fix

floor、ceil、round、fix

作用: 对double、float数据取整;
头文件: math.h

floor(x):不大于x的最大整数;
ceil(x):不小于x的最小整数;
round(x):四舍五入到最近整数;
fix(x):截断取整函数。

floor(-2.1) = -3;
floor(2.1) = 2;
ceil(-2.1) = -2;
ceil(2.1) = 3;
round(2.1) = 2;
round(2.6) = 3;
round(-2.1) = -2;
round(-2.6) = -3;
fix(-2.1) = -2;
fix(2.1) = 2
fix(-2.6) = -2;
fix(2.6) = 2
原文地址:https://www.cnblogs.com/silentteen/p/7991200.html