2.Math.html 942 B

1234567891011121314151617181920212223242526272829
  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. <!--
  10. 变量:
  11. var xxx;
  12. 字面量:
  13. 1 2 5 8 true hello
  14. -->
  15. <script>
  16. document.write(Math.PI + '<br/>');//常量π
  17. document.write(Math.E);//常量
  18. console.log(Math.ceil(3.1456));//向上取整
  19. console.log(Math.floor(3.1456));//向下取整
  20. console.log(Math.abs(-8));//绝对值
  21. console.log(Math.round(10.28));//四舍五入
  22. console.log(Math.random() * 10);//随机数
  23. console.log(Math.pow(3,3));//x的y次幂
  24. console.log(Math.sqrt(16));//x的算数平方根
  25. // 固定范围内随机数
  26. // 固定范围内随机数取整(四舍五入)
  27. </script>
  28. </body>
  29. </html>