math对象

静态属性

Math.E :常量e。返回自然对数的底数:2.718281828459045
Math.PI :常量π。返回圆周率的值 :3.141592653589793

静态方法

Math.sin(value) :正弦函数
Math.cos(value) :余弦函数
Math.tan(value) :正切函数
Math.asin(value) :反正弦函数
Math.acos(value) :反余弦函数
Math.atan(value) :反正切函数
Math.abs(value) :返回绝对值

示例:
Math.abs('123'); // => 123 :纯数字字符串
Math.abs('-123'); // => 123
Math.abs('123a'); // => NaN :非纯数字字符串
Math.ceil(value) : 对一个数向上取整,并不是四舍五入

示例:
Math.ceil(2.7); // => 3
Math.ceil(2.3); // => 3 :2.3 向上取整返回 3
Math.ceil(-2.7); // => -2
Math.ceil(-2.3); // => -2
Math.ceil('2.7'); // => 3 :纯数字字符串
Math.ceil('2.7a'); // => NaN :非纯数字字符串
Math.floor(value) :对一个数向下取整,并不是四舍五入

示例:
Math.floor(2.7); // => 2
Math.floor(2.3); // => 2
Math.floor(-2.7); // => -3 :-2.7 向下取整返回 -3
Math.floor(-2.3); // => -3
Math.floor('2.7'); // => 2 :纯数字字符串
Math.floor('2.7a'); // => NaN :非纯数字字符串
Math.random() :返回一个伪随机数,大于0,小于1.0

示例:
Math.random(); // => 0.8982374747283757
Math.round(value) : 四舍五入后取整

示例:
Math.round(2.5); // => 3
Math.round(2.4); // => 2
Math.round(-2.6); // => -3
Math.round(-2.5); // => -2 :-2.5四舍五入为 -2
Math.round(-2.4); // => -2
Math.round('2.7'); // => 3 :纯数字字符串
Math.round('2.7a'); // => NaN :非纯数字字符串

JS验证码

powered by GitbookEdit Time: 2023-04-08 10:28:32