Home » JavaScript Math trunc() Method

JavaScript Math trunc() Method

by Online Tutorials Library

JavaScript Math trunc() method

The JavaScript math trunc() method removes the fractional part of the given number and returns the remaining integer part only.

Syntax

The trunc() method is represented by the following syntax:

Parameter

num – A number.

Return

The integer part of the given number.

JavaScript Math trunc() method example

Here, we will understand trunc() method through various examples.

Example 1

Let’s see an example to print integer part of the given numbers.

Test it Now

Output:

12  0  

Example 2

In this example, we will use trunc() method with negative numbers.

Test it Now

Output:

-12  0  

Example 3

Here, you can test trunc() method with your own test cases.

Test it Now

Next TopicJavaScript Math

You may also like