一、Math属性
E:返回算术常量 e,即自然对数的底数(约等于2.718) LN2:返回 2 的自然对数(约等于0.693) LN10:返回 10 的自然对数(约等于2.302) LOG2E:返回以 2 为底的 e 的对数(约等于 1.414) LOG10E:返回以 10 为底的 e 的对数(约等于0.434) PI:返回圆周率(约等于3.14159) SQRT1_2:返回 2 的平方根的倒数(约等于 0.707) SQRT2:返回 2 的开平方根(约等于 1.414)
二、Math常用方法示例
document.write(Math.PI);/*返回PI的值*/ document.write(Math.SQRT2);/*返回2的开平方根*/ var a = -1; document.write(Math.abs(a));/*求绝对值*/ document.write(Math.max(2,3));/*取最大值*/ document.write(Math.min(1,2));/*取最小值*/ document.write(Math.round(0.555));/*四舍五入*/ document.write(Math.random());/*取随机数0-1之间*/