版权声明:转载声明原作者及链接 https://blog.csdn.net/ICY___/article/details/86517387
Math 对象用于执行数学任务,也就是数学计算,对于常见的运算方法,js都有内置。
直接上代码
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script>
/*Math 对象里面 有自己封装的方法*/
console.log(Math);
console.log(Math.PI);//3.14
/*取绝对值*/
console.log(Math.abs(-1));
/*向上取整*/
console.log(Math.ceil(2.1));
/*向下取整*/
console.log(Math.floor(2.7));
/*四舍五入取整*/
console.log(Math.round(4.5));
/*最大最小*/
console.log(Math.min(1, 2, 5));
console.log(Math.max(1, 2, 5));
/*随机数 0-1*/
console.log(Math.floor(Math.random() * 5 + 5));
/*Math.sin()
Math.cos()
Math.tan()
Math.arc()*/
/*Math.pow() 次幂*/
console.log(Math.pow(2, 3));
/*一个小球 sin运动*/
</script>
</head>
<body>
</body>
</html>