zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Sublime安装package control的操作
    Sublime的简单操作
    C# 泛型方法
    C# 数组的讲解(ArrayList 与List的区别)
    免费的天气API
    bootstrapValidator的验证
    sqlServer 多行合并为一行
    bootstrap的安装注意
    SQL数据库中把一个表中的数据复制到另一个表中
    JavaScript的误区
  • 原文地址:https://www.cnblogs.com/001yjk/p/10651816.html
Copyright © 2011-2022 走看看