现在的位置: 首页 > 综合 > 正文

关于floor和ceil函数的解释

2019年10月01日 ⁄ 综合 ⁄ 共 327字 ⁄ 字号 评论关闭

floor(x)  is the largest integer not greater than x , 也就是,floor(x) 返回的是小于等于x的所有整数中最大的整数,简单的说,就是去掉x的小数部分的整数

ceil(x)  is the smallest integer not less than x,也就是,ceil(x) 返回的是大于等于x的所有整数中最小的整数,简单的说,就是如果x是整数,则返回该数,如果x不是整数,则不管小数部分是多少,都进一位然后返回。


例如:

floor(3.2)= 3;

ceil(3.2)= 4;

floor(4)= 4;

ceil(4)= 4;


可参考:

http://www.mathsisfun.com/sets/function-floor-ceiling.html

抱歉!评论已关闭.