js笔记之Math random()、ceil()、floor()、round()
生活随笔
收集整理的這篇文章主要介紹了
js笔记之Math random()、ceil()、floor()、round()
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
本文轉(zhuǎn)自:http://blog.sina.com.cn/s/blog_7e4815650100wrfz.html
JavaScript: The Definitive Guide, 4thEdition中對Math.ceil(),Math.floor()與Math.round()三個函數(shù)的定義。
Math.random()
| 返回 0 ~ 1 之間的隨機數(shù)。 |
Math.ceil()
ceil() 方法可對一個數(shù)進行上舍入。
參數(shù)必須是一個數(shù)值。返回值大于等于 x,并且與它最接近的整數(shù)。
Math.floor()
floor() 方法可對一個數(shù)進行下舍入。
參數(shù)可以是任意數(shù)值或表達式。返回值小于等于 x,且與 x 最接近的整數(shù)。
Math.round()
round() 方法可把一個數(shù)字舍入為最接近的整數(shù)
參數(shù)必須是一個數(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));
總結(jié)
以上是生活随笔為你收集整理的js笔记之Math random()、ceil()、floor()、round()的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jquery遍历函数siblings()
- 下一篇: jquery lt选择器与gt选择器