加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个

发布时间:2020-12-14 05:22:11 所属栏目:Java 来源:网络整理
导读:首先还是看看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 . ------------------------------

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读