close

 

JavaScript無條件進位的計算可用Math.ceil()。無條件捨去可用Math.floor()

Math.ceil(.95);    // 1
Math.ceil(4);      // 4
Math.ceil(7.004);  // 8
Math.ceil(-0.95);  // -0
Math.ceil(-4);     // -4
Math.ceil(-7.004); // -7

Math.floor(.95);   // 0
Math.floor(4);     // 4
Math.floor(7.004); // 7
Math.floor(-0.95); // -1
Math.floor(-4);    // -4
Math.floor(-7.004);// -8

 

--

轉自 https://matthung0807.blogspot.com/2017/11/javascript.html

--

arrow
arrow
    全站熱搜

    dizzy03 發表在 痞客邦 留言(0) 人氣()