ES6 Math.trunc( x )

它返回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

它将数字四舍五入为最接近的整数。语法Math.round( x ) ;参数X - 代表一个数字例console.log("---Math.round()---")console.log("Math.r ...