JS Math对象

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Math对象</title>
</head>
<body>
    <script>
        document.write(Math.PI) // 圆周率
        document.write("<br/>")
        document.write(Math.SQRT2) // 2 的平方根
        document.write("<br/>")
        //向上取整
        document.write(Math.ceil(3.133)); //4
        document.write("<br/>")
        //向下取整
        document.write(Math.floor(5.324234)) //5
        document.write("<br/>")
        //幂运算
        document.write(Math.pow(4, 2)) //16
        document.write("<br/>")
        //平方根
        document.write(Math.sqrt(4)) //2
        document.write("<br/>")
        //最小值
        document.write(Math.min(1, 2, 3, 4, 5, 6, 7)) //1
        document.write("<br/>")
        //最大值
        document.write(Math.max(1, 2, 3, 4, 5, 6, 7)) //7
        document.write("<br/>")
        //0~1之间的随机数
        document.write(Math.random())
        document.write("<br/>")
        //1~100之间的随机数
        /*  for (var a = 0; a <= 101; a++) {
              var s = Math.floor(Math.random() * 100) + 1
              document.write(s + "<br/>")
          }*/
        //Math.round  四舍五入(仅保留整数位)
    </script>
</body></html>
原文地址:https://www.cnblogs.com/001yjk/p/10651816.html