zoukankan      html  css  js  c++  java
  • javascript--Math对象

    Math数学对象

    Math.min (1, 2, 3);//获取若干个数中的最小值

    Math.max (1, 2, 3);//获取若干个数中的最大值

    Math.abs (-1.5);//返回数的绝对值

    Math.ceil (1.1);// 2 上舍入

    Math.floor (1.9);// 1 下舍入

    Math.round (1.6);//四舍五入

    Math.random ();//0~1的随机数

    Math.toSource ();//返回该对象的源代码

    Math.abs()

    eg: var x = -1.5;

    //var y = Math.abs(x);

    //document.write(y);

    document.write(Math.abs(x));

    求任意范围内随机数的方法为:Math.floor(Math.random() * (b - a + 1) + a);

    eg: 求15-25之间的随机数(10个);

    var  array1 = [];

    for ( var i = 0; i < 10; i++ ) {

         array1[i] = Math.floor( Math.random() * 11 + 15 );

    }

    for ( var i = 0; i < array1.length; i++ ) {

        document.write( array1[i] );

        //console.log( array1[i] );

    }

    Math.toSource()方法;

    eg: 

    <script type="text/javascript" charset="utf-8">
      function student( name, age, profession) {
        this.name = name;
        this.age = age;
        this.profession = profession;
      }
      var stu = new student('小七', '20', 'major of computer application');
      // var result = stu.toSource();
      document.write(stu.toSource());
    </script>

  • 相关阅读:
    MySQL慢日志
    百万级数据生成。
    layui的数据表格加上操作
    WINDOWS命令行关闭本地占用的端口
    项目中路径问题
    linux服务器上使用find查杀webshell木马方法
    mysql锁分析相关的几个系统视图
    Centos7中网络及设备相关配置
    centos7版本中ssh相关的设置
    mysql权限参考
  • 原文地址:https://www.cnblogs.com/zhao12354/p/5713819.html
Copyright © 2011-2022 走看看