Home >>JavaScript Math Reference >JavaScript trunc() Method

JavaScript trunc() Method

JavaScript trunc() Method

JavaScript math.trunc() method is a static method of math and is used to return the integer part of a floating-point by removing the fractional digit of the given number and returns the remaining integer part only. You can always used as math.trunc(), rather than you created as a method of a math object.

Syntax:

Math.trunc(value)

Parameter Values

Parameter Description
x It required a number

Browser Support

Method Chrome Edge Firefox Safari Opera
trunc() 38 12 25 8 25

Here is an example of JavaScript trunc() Method:

<html>
<body>
<button onclick="myTrunc()">Click me</button>
<p id="trunc"></p>
<script>
function myTrunc() 
{
  document.getElementById("trunc").innerHTML = Math.trunc(12.67);
}
</script>
</body>
</html>
Output:

 

Example 2:

<html>
<body>
<script> 
document.write(Math.trunc(-0.567));		 
</script> 
</body>
</html>
Output: