js中Math.floor(),Math.round(),Math.ceil()
1、Math.floor() ,Math.round()方法执行的是取整计算,它们得到的是与之最接近的整数当参数没有的时候,返回你NaNMath.floor()NaNMath.round()NaN
2、我们再使用Math.floor()传入其它参数看看,如下所示。可以看出返回的都是比它小的,最接近它的整数Math.floor(2.9)2Math.floor(-2.9)-3Math.floor(-0.5)-1Math.floor(-0.9)-1Math.floor(0.9)0Math.floor(1.9)1
3、Math.round() 方法可把一个数字四舍五入为最接近的墙绅褡孛数。可以看出Math.round(),的使用和我们平时使用的四舍五入类似,它返回的是最接近它的整数Math.round(1.2)1Math.round(1.6)2Math.round(-1.6)-2Math.round(0.9)1Math.round(0.49)0Math.round(0.01)0Math.round(-0.01)-0Math.round(-0.4)-0
4、ceil() 方法是向上取整计算,它返回的是大于或等于参数的整数数据同样Math.ceil()没传入参数也是返回NaNMath.ceil()NaN
5、ceil猾诮沓靥() 方法是向上取整计算,它和floor其实刚好相反,下面我们传入一些参数来看看该方法,可以看出返回的都是比它大的,最接近它的整数Math.ceil()NaNMath.c髫潋啜缅eil(1.2)2Math.ceil(-1.2)-1Math.ceil(22.10)23Math.ceil(77.10)78Math.ceil(76.9999)77Math.ceil(-76.9999)-76