天天看点

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():指定数字留几位小数点,四舍五入,并将数字转化为字符串。

将数字保留指定位,返回的是字符串的类型。

继续阅读