首先还是看看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 anumber 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() 我们数学中常用到的四舍五入取整。
【JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解】相关文章:
★ JavaScript的Backbone.js框架的一些使用建议整理
★ JavaScript中的Math.LOG2E属性使用详解
★ 介绍JavaScript中Math.abs()方法的使用
★ JavaScript中用于四舍五入的Math.round()方法讲解
★ JavaScript中的setUTCDate()方法使用详解