首頁 > web前端 > js教程 > 主體

JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解_基础知识

WBOY
發布: 2016-05-16 18:28:11
原創
1358 人瀏覽過

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

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!