码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-08-12 18:32:24      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

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

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

标签:

原文地址:http://www.cnblogs.com/maoyazhi/p/4724800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!