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

posted on 2016-03-06 09:53  silentteen  阅读(203)  评论(0编辑  收藏  举报