JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解

时间:2010-04-29    点击:134   

首先还是看看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() 我们数学中常用到的四舍五入取整。

js 父窗口控制子窗口的行为-打开,关闭,重定位,回复
jquery+json 通用三级联动下拉列表
javascript中的变量是传值还是传址的?
js获取当前select 元素值的代码
jQuery 锚点跳转滚动条平滑滚动一句话代码
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved