JavaScript數值的math方法

        var n = 12.34;
        var m = 23;
        //ceil  向上取整
        console.log(Math.ceil(n));
        // floor 向下取整
        console.log(Math.floor(n));
        // max  min 
        console.log(Math.max(n, m));
        //random 0-1隨機取數(浮點數)
        //隨機取200-500
        var a = Math.random();
        var b = 200+a*300;
        var c = Math.floor(b);
        console.log(a, b, c);  //0.44083597885952663 332.250793657858 332

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章