ES6 - Math round() 函式



對數字進行四捨五入,使其接近於最接近的整數。

語法

Math.round( x ) ;      

引數

  • X - 表示一個數字

例子

console.log("---Math.round()---") 
console.log("Math.round(7.2) : "+Math.round(7.2)) 
console.log("Math.round(-7.7) : "+Math.round(-7.7))          

輸出

---Math.round()--- 
Math.round(7.2) : 7 
Math.round(-7.7) : -8         
廣告
© . All rights reserved.