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

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