123456789101112131415161718192021222324252627282930313233 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // Math 对象
- document.write(Math.PI + '<br>')//常量
- document.write(Math.E)//常量
- var a = 4.6;
- // Math.ceil 向上取整
- console.log(Math.ceil(a))
- // Math.floor 向下取整
- console.log(Math.floor(a))
- // Math.abs 绝对值
- console.log(Math.abs(a))
- // Math.round 四舍五入
- console.log(Math.round(a))
- // Math.random 随机数
- console.log(Math.random())
- // Math.round(Math.random() * (y-x) + x)
- // 四舍五入 随机获取 3-10的整数
- console.log(Math.round(Math.random() * (10-3) + 3));
- console.log(Math.sqrt(81)); // Math.sqrt 算数平方根
- console.log(Math.pow(2,3));//Math.pow x的y次幂
- </script>
- </body>
- </html>
|