JavaScript | Math.trunc( ) Function

The Math.trunc() function in JavaScript 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 function accepts a single parameter value . It is the floating-point number which is to be sent to the Math.trunc() function.

Return Value: The Math.trunc() function returns the integer part of the given number.

Below example illustrates the Math.trunc() function in JavaScript:



  1. When a positive number of float type is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    15
  2. When a negative number of float type is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    -15
  3. When a positive number between 0 and 1 is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    0
  4. When a negative number between 0 and 1 is passed as a parameter:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    0


My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.