ES6 - 数学 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