ceil():将小数部分一律向整数部分进位。
如:
Math.ceil(12.2)//返回13
Math.ceil(12.7)//返回13
Math.ceil(12.0)// 返回12
floor():一律舍去,仅保留整数。
如:
Math.floor(12.2)// 返回12
Math.floor(12.7)//返回12
Math.floor(12.0)//返回12
round():进行四舍五入
如:
Math.round(12.2)// 返回12
Math.round(12.7)//返回13
Math.round(12.0)//返回12
js 常用到的几个数学函数
最新推荐文章于 2022-10-22 14:32:56 发布
本文详细介绍了数学函数ceil、floor和round的功能及用法。ceil函数会将小数部分一律向整数部分进位;floor函数则会一律舍去小数部分,仅保留整数部分;round函数会根据数值的小数部分进行四舍五入。
567

被折叠的 条评论
为什么被折叠?



