Math数学对象

Math

Math是一个数学对象。

 // Math 数学对象
        var arr = new Array();
        arr = [1, 5, 7, 9]
        console.log(arr);
        console.log(Math.PI);
        console.log(Math.max(1, 5, 7, 9)); //9
        console.log(Math.min(1, 5, 7, 9)); //1
        console.log(Math.max()); // -infinity
        // Geometric Placement

        // 绝对值方法
        console.log(Math.abs(1)); //1
        console.log(Math.abs(-1)); //1
        console.log(Math.abs('-1')); // 1 隐式转换
        console.log(Math.abs('pink')); // NaN

        // 三个取整的方法 floor(向上取整) ceil(向下取整) round(四舍五入)
        console.log(Math.floor(3.14)); //3
        console.log(Math.ceil(3.14)); //4
        console.log(Math.round(3.14)); //3
        console.log(Math.round(-1.5)); //-1   .5的是时候,往大的取。
        console.log(Math.round(-1.9)); // -2

 

posted @ 2021-09-27 22:08  二王戏木  阅读(37)  评论(0)    收藏  举报