Math物件 函式總結

2021-10-04 06:29:27 字數 836 閱讀 5221

math的官方函式

1.math.random()

作用:隨機產生0-1之間的數,不包括1

var t = parseint(math.random()*10);

隨機取出0~10之間的乙個整數,不包括10

2.math.round(n)

作用:四捨五入取整

math.round(4.2);結果是4

3.math.ceil(n)

作用:向上取整 (比n大的最小整數)

math.ceil(4.2)

4.math.floor(n)

作用:向下取整(捨去小數字)

math.floor(4.2) 結果為4

5.math.max

作用:求最大數

math.max(8,2,1,9,6,20,7) 得結果為20

6.math.min

作用:求最小數

math.max(8,2,1,9,6,20,7) 得結果為1

7.math.pow(底數,指數)

作用:求冪

math.pow(2,5) :求 2的5次方

8.math.sqrt(n)

作用:開根號

math.sqrt(25) 結果為5

9.math.abs(n)

作用:求絕對值

math.abs(-8) 結果為8

math模組常用函式總結

函式 描述格式 返回值ceil 向上取整操作 math.ceil 數值 整型floor 向下取整操作 對比內建round math.floor 數值 整型pow 計算乙個數值的n次方 math.pow 底數,指數 浮點型sqrt 開平方運算 math.sqrt 數值 數值fabs 計算乙個數值的絕對...

Math(數學物件)

math 算術函式和常量 math.abs 計算絕對值 math.acos 計算反余弦值 math.asin 計算反正弦值 math.atan 計算反正切值 math.atan2 計算從x軸到乙個點之間的角度 math.ceil 對乙個數上捨入 math.cos 計算余弦值 math.e 算術常量e...

math物件方法

1.求某個數的多次方 var res math.pow 5,10 求5的十次方 console.log res 2.四捨五入 var res math.round 3.0001 從小數點後一位開始四捨五入 console.log res 3.求絕對值 var res math.abs 10 絕對值,...