70
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.
Output:
12 0
Example 2
In this example, we will use trunc() method with negative numbers.
Output:
-12 0
Example 3
Here, you can test trunc() method with your own test cases.
Next TopicJavaScript Math