JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三個函數(shù)的理解
首先還是看看JavaScript: The Definitive Guide, 4th Edition中對三個函數(shù)的定義。
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.
以前一直會三個函數(shù)的使用產(chǎn)生混淆,現(xiàn)在通過對三個函數(shù)的原型定義的理解,其實(shí)很容易記住三個函數(shù)。
現(xiàn)在做一個總結(jié):
1. Math.ceil()用作向上取整。
2. Math.floor()用作向下取整。
3. Math.round() 我們數(shù)學(xué)中常用到的四舍五入取整。
相關(guān)文章
Javascript中arguments和arguments.callee的區(qū)別淺析
這篇文章主要介紹了Javascript中arguments和arguments.callee的區(qū)別淺析,本文用一個實(shí)例來理解它們的區(qū)別,需要的朋友可以參考下2015-04-04
javascript函數(shù)作用域?qū)W習(xí)示例(js作用域)
javascript中沒有塊級作用域,取而代之的javascript使用的是函數(shù)作用域,下面使用示例學(xué)習(xí)一下js作用域的使用方法2014-01-01
javascript基礎(chǔ)知識大集錦(一) 推薦收藏
主要知識點(diǎn):js數(shù)組,數(shù)字函數(shù),字符串函數(shù),表單驗(yàn)證,hashMap,堆棧,日期函數(shù),call函數(shù) 等。2011-01-01
在JavaScript中處理時間之getHours()方法的使用
這篇文章主要介紹了在JavaScript中處理時間之getHours()方法的使用,是JS入門學(xué)些中的基礎(chǔ)知識,需要的朋友可以參考下2015-06-06
nodejs的require模塊(文件模塊/核心模塊)及路徑介紹
在nodejs中,模塊大概可以分為核心模塊和文件模塊,核心模塊是被編譯成二進(jìn)制代碼,引用的時候只需require表示符即可,文件模塊,則是指js文件、json文件或者是.node文件2013-01-01
javascript學(xué)習(xí)筆記(十五) js間歇調(diào)用和超時調(diào)用
javascript學(xué)習(xí)筆記之js間歇調(diào)用和超時調(diào)用介紹,學(xué)習(xí)js的朋友可以參考下2012-06-06

