2.Math.html 749 B

123456789101112131415161718192021222324
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. console.log(Math.PI);//π
  11. console.log(Math.E);
  12. console.log(Math.ceil(54.23)); //向上取整
  13. console.log(Math.floor(7.9)); //向下取整
  14. console.log(Math.round(4.26)); //四舍五入
  15. console.log(Math.abs(-2));//绝对值
  16. console.log(Math.sqrt(49));//算术平方根
  17. console.log(Math.pow(2,4));//x的y次幂
  18. console.log(Math.random() * 12)//随机数
  19. // 固定范围内随机数取整
  20. Math.round(Math.random() * (y-x) + x);
  21. </script>
  22. </body>
  23. </html>