Last Updated : 15 Jul, 2024
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.
Syntax:Math.trunc(value)Parameters:
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
JavaScript
console.log(Math.trunc(15.56));
Example 2: Truncating Negative Number
When a negative number of a float type is passed as a parameter
JavaScript
console.log(Math.trunc(-15.56));
Example 3: Passing Number between 0 and 1.
Here, we are passing number between 0 and 1.
JavaScript
console.log(Math.trunc(0.236));
We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.
Supported Browsers:RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4