ceil()和floor()的函数原型:
double ceil(double x); smallest integer not less than x double floor(double x); largest integer not greater than x
|
(1)假设x为4.4,则ceil(4.4)为5, floor(4.4)为4 。
(2)假设x为4,则ceil(4)为4, floor(4)为4。
(3)若想对x四舍五入,则
if(x > 0.0) return int(x + 0.5); else return int(x - 0.5);
|
阅读(835) | 评论(0) | 转发(0) |