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