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>

  • 相关阅读:
    IDEA常用快捷键
    IDEA的使用
    IDEA的常用设置
    IDEA的下载安装
    004-解决多线程安全问题
    002-多线程的创建
    Java中字符串与日期之间的转换
    select标签的字体居中问题
    IntelliJ IDEA常用快捷键
    div小技巧之子元素垂直居中
  • 原文地址:https://www.cnblogs.com/zhao12354/p/5713819.html
Copyright © 2011-2022 走看看