您好,登錄后才能下訂單哦!
作用:用來返回參數(shù)的絕對值
Math.abs(-3); //輸出3
Math.abs(3); //輸出3
作用:返回參數(shù)中最大的那個值
Math.min()
作用:返回參數(shù)中最小的那個值
Math.max(2,-10,45) //輸出45
假若傳的是一個數(shù)組,那需要借助apply來得到數(shù)組中的最大值或者最小值
var arr=[23,-9,67,34,-89,0];
Math.min.apply(null,arr); //輸出-89
作用:返回小于參數(shù)值的最大整數(shù)
Math.floor(3.2) //輸出3
Math.floor(-3.2) //輸出-4
作用:返回大于參數(shù)值的最小整數(shù)
Math.ceil(3.2) //輸出4
Math.ceil(-3.2) //輸出-3
作用:四舍五入
Math.round(0.1) //輸出0
Math.round(0.6) //輸出1
Math.round(-1.1) //輸出-1
Math.round(-1.5) //輸出-1
Math.round(-1.6) //輸出-2
作用:返回以第一個參數(shù)為底數(shù),第二個參數(shù)為冪的指數(shù)值
Math.pow(2,2) //輸出4
Math.pow(3,4) //輸出81
作用:返回參數(shù)值的平方根,如果參數(shù)是一個負值,則返回NaN
Math.sqrt(4) //輸出2
Math.sqrt(-81) //輸出NaN
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。