Javatpoint Logo
Javatpoint Logo

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





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA