Math.random();隨機數的取整

今天搞背景色rbg的測試的時候發現Math這邊的東西有點生疏了特來複習一下。
//向下取整 floor
Math.floor(0.99) //輸出0
Math.floor(-0.99) //輸出-1
//向上取整 ceil
Math.ceil(0.99)  //輸出1
Math.ceil(-0.99)  //輸出0
//四捨五入
Math.round(1.9) //輸出2
Math.round(-1.45) //輸出 -1

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