ES6 - Math.trunc()


Advertisements

This function returns the integer part of a number by removing any fractional digits.

Syntax

The syntax stated below is for the function Math.trunc(), where, X − represents a number.

Math.trunc( x ) ;

Example

<script>
   console.log(Math.trunc(-3.5)) // -3
   console.log(Math.trunc(-3.6)) // -3
   console.log(Math.trunc(3.5)) // 3
   console.log(Math.trunc(3.6)) // 3
</script>

The output of the above code will be as shown below −

-3
-3
3
3
Advertisements