The Wayback Machine - https://web.archive.org/web/20240118173912/https://www.geeksforgeeks.org/javascript-math-trunc-method/
Open In App
Related Articles

JavaScript Math trunc() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The Javascript  Math.trunc() method is used to return the integer part of a floating-point number by removing the fractional digits. In other words, the Math.trunc() function cuts off the dot and the digits to the right of it. 

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: 

Below is an example of the Math trunc() Method.

Example: When a positive float number passed as a parameter 

javascript




console.log(Math.trunc(15.56));


Output

15

More coding examples are given below for a better understanding:

Example 1: When a negative number of a float type is passed as a parameter 

javascript




console.log(Math.trunc(-15.56));


Output

-15

Example 2: When a positive number between 0 and 1 is passed as a parameter.

javascript




console.log(Math.trunc(0.236));


Output

0

Example 3: When a negative number between 0 and 1 is passed as a parameter.

javascript




console.log(Math.trunc(-0.236));


Output

-0

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:

  • Google Chrome 38 and above
  • Firefox 25 and above
  • Opera 25 and above
  • Safari 8 and above
  • Edge 12 and above

Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 01 Aug, 2023
Like Article
Save Article
Share your thoughts in the comments
Similar Reads
Complete Tutorials