作家
登录

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

作者: 来源:www.28hudong.com 2013-03-30 01:37:10 阅读 我要评论

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

  推荐阅读

  Javascript JSQL,SQL无处不在,

其实还可以这样操作: 复制代码 代码如下: var Room = [ { ID: 'bot', name: 'test', sex: true }, { ID: 2, name: 'test8', sex: true }, { ID: 3, name: 'test5', sex: false }, { ID: 4, name: 'test2', sex: t>>>详细阅读


本文标题:JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解

地址:http://www.17bianji.com/kaifa2/JS/26469.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)