JavaScript Math.trunc() | Get integer part of a number

The JavaScript Math.trunc() method is used when we need to find the integer part of a number. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

  <p id="xyz"></p>

  <script>
    let num = 137.4356;
    document.getElementById("xyz").innerHTML = Math.trunc(num);
  </script>
   
</body>
</html>
Output

JavaScript Math.trunc() Syntax

The syntax of Math.trunc() method in JavaScript is:

Math.trunc(x)

The parameter x is required, refers to number.

The Math.trunc() method returns the integer part of specified number x.

Other methods to do similar job

Here are the list of methods that are used to either round a number in other way, or to do similar type of job.

JavaScript Online Test


« Previous Tutorial Next Tutorial »