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
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
相关文章推荐
- js笔记
- Javascript 面向对象
- 从本地JSON文件中读取数据
- 一张地图告诉你,只JavaScript不够!
- js实现图片轮播效果
- JS学习第九天----数组
- 详细解读JavaScript的跨浏览器事件处理
- javascript ipz127
- 随机选择(JS)
- 【翻译】Ext JS最新技巧――2015-8-11
- 【翻译】Ext JS最新技巧——2015-8-11
- 【翻译】Ext JS最新技巧——2015-8-11
- 【翻译】Ext JS最新技巧——2015-8-11
- js实现图片浮动
- JavaScript日期格式化及解析
- pom.xml 添加 JSON依赖的配置
- 了解ASP.NET MVC几种ActionResult的本质:JavaScriptResult & JsonResult
- JS判断数据是否是JSON类型
- 推荐:自定义滚动条插件(tscroll.js)
- js密码强度