js的Math常用方法

2021-06-22 11:32:00 字數 648 閱讀 6640

round():

document.write(math.round(0.60) + "

")document.write(math.round(0.50) + "

")document.write(math.round(0.49) + "

")document.write(math.round(-4.40) + "

")document.write(math.round(-4.60))

結果:110

-4-5

math.random()的範圍在0--1之間,但是不包括1

math.random()*3-----0 1 2

math.random()*3+1-----0 1 2

math.floor(math.random()*3+1)------0 1 2

搭配向下取整math.floor()

向上取整:math.ceil()

四捨五入:math.round()

abs(x) 返回數的絕對值 1 2 3 

pow(x,y) 返回 x 的 y 次冪 1 2 3 

sqrt(x) 返回數的平方根 1 2 3 

math.min(5,7)返回兩個數較小的那個

math.max(5,7)返回兩個數較大的那個

js中常用的Math方法

math.min 用於確定一組數值中的最小值。math.max 用於確定一組數值中的最大值。alert math.min 2,4,3,6,3,8,0,1,3 最小值alert math.max 4,7,8,3,1,9,6,0,3,2 最大值 2.捨入方法 math.ceil 執行向上捨入,即它總是將...

JS 中常用的 Math 方法

1.取最大值 和 取最小值 math.min 取一組數值的最小值 math.max 取一組數值的最大值alert math.min 2,4,3,6,3,8,0,1,3 最小值 alert math.max 4,7,8,3,1,9,6,0,3,2 最大值 2.捨入方法 math.round 標準捨入,...

js中math函式的常用方法

math.abs j絕對值 math.ceil 整數 向上取整和向下取整 console.log math.ceil 12.95 13 console.log math.floor 12.3 12 math.round 四捨五入 注意 正數時,包含5是向上取整,負數時包含5是向下取整。math.ra...