VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-math-trunc-method/

⇱ JavaScript Math trunc() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Math trunc() Method

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:

  • value. It is the floating-point number that is to be sent to the Math.trunc() function.

Return Value:

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 


Output
15

Example 2: Truncating Negative Number

When a negative number of a float type is passed as a parameter 


Output
-15

Example 3: Passing Number between 0 and 1.

Here, we are passing number between 0 and 1.


Output
0

We have a complete list of Javascript Math Objects methods, to check those please go through this article.

Supported Browsers:

  • Chrome 51
  • Edge 15
  • Firefox 54
  • Safari 10
  • Opera 38
Comment