Skip to content
Related Articles

Related Articles

Improve Article

JavaScript Math trunc( ) Method

  • Last Updated : 10 Jul, 2020

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

  • Example: When a positive float number passed as a parameter




    <script type="text/javascript">
             document.write(Math.trunc(15.56));         
    </script>
  • Output:
    15

The Math.trunc() method is used to return the integer part of a floating-point number by removing the fractional digits. In other words, 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 which 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:
Program 1: When a negative number of float type is passed as a parameter




<script type="text/javascript">
         document.write(Math.trunc(-15.56));         
</script>

Output:

-15

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




<script type="text/javascript">
         document.write(Math.trunc(0.236));         
</script>

Output:

0

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




<script type="text/javascript">
         document.write(Math.trunc(-0.236));         
</script>

Output:

0

Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari



My Personal Notes arrow_drop_up
Recommended Articles
Page :