ES6 - Math trunc() 函式



返回 x 的整數部分(刪除所有小數部分)。

語法

Math.trunc( x ) ;      

引數

  • x − 表示數字

示例

console.log("---Math.trunc()---") 
console.log("Math.trunc(7.7) : "+Math.trunc(7.7)) 
console.log("Math.trunc(-5.8) : "+Math.trunc(-5.8))          

輸出

---Math.trunc()--- 
Math.trunc(7.7) : 7 
Math.trunc(-5.8) : -5          
廣告
© . All rights reserved.