我是靠谱客的博主 畅快枫叶,最近开发中收集的这篇文章主要介绍JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

最后

以上就是畅快枫叶为你收集整理的JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解的全部内容,希望文章能够帮你解决JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(178)

评论列表共有 0 条评论

立即
投稿
返回
顶部