首页 > Web开发 > 详细

JS Math对象

时间:2019-04-03 22:11:29      阅读:141      评论:0      收藏:0      [点我收藏+]
<!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>

JS Math对象

原文:https://www.cnblogs.com/001yjk/p/10651816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!