您的位置:首页 > Web前端 > JavaScript

javascript中Math ceil(),floor(),round()三个函数的对比

2015-08-12 16:39 513 查看
Math.ceil()执行的是向上舍入

Math.floor()执行向下舍入

Math.round()执行标准舍入

一下是一些补充:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: