![]() |
VOOZH | about |
The Math.trunc() method in JavaScript returns the integer part of a number by removing its fractional part. It essentially truncates the decimal portion of a number towards zero, resulting in an integer.
For positive numbers, it's equivalent to flooring the number, while for negative numbers, it's akin to ceiling the number.
Math.trunc(value)This method accepts a single parameter as mentioned above and described below:
The Math.trunc() method returns the integer part of the given number. More codes for the above method are as follows:
Example 1: Truncating Positive Number
When a positive float number passed as a parameter
15
Example 2: Truncating Negative Number
When a negative number of a float type is passed as a parameter
-15
Example 3: Passing Number between 0 and 1.
Here, we are passing number between 0 and 1.
0
We have a complete list of Javascript Math Objects methods, to check those please go through this article.