JavaScipt中的Math.ceil()、Math.floor()、Math.round()三個函數的理解_基礎知識
來源:懂視網
責編:小采
時間:2020-11-27 20:49:02
JavaScipt中的Math.ceil()、Math.floor()、Math.round()三個函數的理解_基礎知識
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
導讀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

首先還是看看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() 我們數學中常用到的四舍五入取整。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
JavaScipt中的Math.ceil()、Math.floor()、Math.round()三個函數的理解_基礎知識
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