Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解
2016-06-20 15:10
501 查看
首先还是看看JavaScript: The Definitive Guide, 4th Edition中对三个函数的定义。
Math.ceil(): round a
number up
Arguments: Any numeric value or expression
Returns: The closest integer greater than or equal to
x.
-----------------------------------------------------------------------------------------------
Math.floor(): round a number down
Arguments: Any numeric value or expression
Returns: The closest integer less than or equal to
x.
-----------------------------------------------------------------------------------------------
Math.round(): round to the
nearest integer
Arguments: Any number.
Returns: The integer closest to
x.
以前一直会三个函数的使用产生混淆,现在通过对三个函数的原型定义的理解,其实很容易记住三个函数。
现在做一个总结:
1. Math.ceil()用作向上取整。
2. Math.floor()用作向下取整。
3. Math.round() 我们数学中常用到的四舍五入取整。
转自:http://www.jb51.net/article/23276.htm
Math.ceil(): round a
number up
Arguments: Any numeric value or expression
Returns: The closest integer greater than or equal to
x.
-----------------------------------------------------------------------------------------------
Math.floor(): round a number down
Arguments: Any numeric value or expression
Returns: The closest integer less than or equal to
x.
-----------------------------------------------------------------------------------------------
Math.round(): round to the
nearest integer
Arguments: Any number.
Returns: The integer closest to
x.
以前一直会三个函数的使用产生混淆,现在通过对三个函数的原型定义的理解,其实很容易记住三个函数。
现在做一个总结:
1. Math.ceil()用作向上取整。
2. Math.floor()用作向下取整。
3. Math.round() 我们数学中常用到的四舍五入取整。
转自:http://www.jb51.net/article/23276.htm
相关文章推荐
- 【Oracle】GoldenGate 12.2 OGG-01201 Error reported by MGR : Access denied.
- IntelliJ IDEA / Eclipse 自动生成 Author 注释 签名
- c#一个FTP操作封装类FTPHelper
- System.Types.hpp(77): E2029 'TObject' must be a previously defined class or struct
- 扛得住双11的Mysql---操作系统
- C# 文件转字节数组 byte[]
- checkbox的样式优化
- matlab在循环中保存图片命名不重复
- Flask at Scale (Flask如何适配到大型应用) - PyCon 2016 简明中文翻译
- 九度OJ 1073:杨辉三角形
- 广东海洋大学 电子1151 孔yanfei python语言程序设计 第五周
- 模式识别(Pattern Recognition)学习笔记(三十三)-- Boosting方法之AdaBoost
- web工程目录结构
- 【shell】nmap工具的使用
- js全选 反选
- I.MX6 AW-NB177NF WIFI 驱动移植问题
- vim正则用法
- javascript创建对象
- 静态成员应用
- 开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别