ceil()和floor()用法

899阅读 0评论2010-01-09 gnometerminal
分类:C/C++

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);


上一篇:产生伪随机数
下一篇:没有了