天天看點

Math對象和Number對象的常用方法

Math對象

Math.max(n1,n2,n3,n4):取得最大值

Math.min(n1,n2,n3,n4):取得最小值

Math.PI:獲得π的值

Math.E:獲得e的值

Math.pow(x,y):獲得x的y次方的值

Math.sqrt(x):獲得x的開方數的值

Math.abs(x):獲得絕對值。

Math.floor(x):向下取整

Math.ceil:向上取整

Math.round(x):擷取四舍五入的值。

Math.random():随機取值。

Number對象

toExponential:科學計數法,指數計數法。

toFixed():指定數字留幾位小數點,四舍五入,并将數字轉化為字元串。

将數字保留指定位,傳回的是字元串的類型。

繼續閱讀