JavaScript Math函数的round,pow,sqrt,abs操作
JavaScript Math 对象允许您对数字执行数学任务。
实例
Math.PI; // 返回 3.141592653589793
Math.round()
Math.round(x) 的返回值是 x 四舍五入为最接近的整数:
实例
Math.round(6.8); // 返回 7
Math.round(2.3); // 返回 2
Math.pow()
Math.pow(x, y) 的返回值是 x 的 y 次幂:
实例
Math.pow(8, 2); // 返回 64
Math.sqrt()
Math.sqrt(x) 返回 x 的平方根:
实例
Math.sqrt(64); // 返回 8
Math.abs()
Math.abs(x) 返回 x 的绝对(正)值:
实例
Math.abs(-4.7); // 返回 4.7
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64429.shtml