Javascript Math trunc()

Introduction

The Math.trunc() function returns the integer part of a number by removing fractional digits.

Math.trunc(x) // x is a number.
let a = Math.trunc(13.12337);    
console.log(a);//w  w w  .  j a va 2  s  . c  om
a = Math.trunc(42.84);    
console.log(a);
a = Math.trunc(0.123);    
console.log(a);
a = Math.trunc(-0.123);   
console.log(a);
a = Math.trunc('-1.123'); 
console.log(a);
a = Math.trunc(NaN);      
console.log(a);
a = Math.trunc('foo');    
console.log(a);
a = Math.trunc();  
console.log(a);       



PreviousNext

Related