PHP判断变量是不是整数的方法大全: 一、使用 floor 或 ceil 方法 …
正在浏览:整数
// 向上取整 var ceil = Math.ceil(5 / 2) console.log(‘++++++++++’, ceil) // 3 // 向下取整 var floor = Math.floor(5 / 2) console.log(‘———-‘, floor) // 2 // 四舍五入 var round1 = Math.round(5 / 2), round2 = Math.round(10 / 3)
Math.round(7/2)=4 //四舍五入 Math.ceil(7/2)=4 //强制向上取整 Math.floor(7/2)=3 //强制向下取整 parseInt(7/2)=3 //强行转化,得出最小整数,同Math.floor方法。
