ES6 - Math trunc() Function


Advertisements


It returns the integral part of x (all fractional digits are removed).

Syntax

Math.trunc( x ) ;      

Parameter

  • X − represents a number

Example

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

Output

---Math.trunc()--- 
Math.trunc(7.7) : 7 
Math.trunc(-5.8) : -5          

es6_math.htm

Advertisements