服務熱線
153 8323 9821
JavaScript: The Definitive Guide, 4th Edition中對Math.ceil(),Math.floor()與Math.round()三個函數的定義。
Math.random()
| 返回 0 ~ 1 之間的隨機數。 |
ceil() 方法可對一個數進行上舍入。
參數必須是一個數值。返回值大于等于 x,并且與它最接近的整數。
floor() 方法可對一個數進行下舍入。
參數可以是任意數值或表達式。返回值小于等于 x,且與 x 最接近的整數。
round() 方法可把一個數字舍入為最接近的整數
參數必須是一個數值。返回值與 x 最接近的整數。
document.writeln("Math.ceil(4.8992303)輸出結果:"+Math.ceil(4.8992303)+"<br/>"); document.writeln("Math.floor(4.8992303)輸出結果:"+Math.floor(4.8992303)+"<br/>"); document.writeln("Math.round(4.8992303)輸出結果:"+Math.round(4.8992303)+"<br/><br/>"); document.writeln("Math.ceil(4.29993354)輸出結果:"+Math.ceil(4.29993354)+"<br/>"); document.writeln("Math.floor(4.29993354)輸出結果:"+Math.floor(4.29993354)+"<br/>"); document.writeln("Math.round(4.29993354)輸出結果:"+Math.round(4.29993354));
