How can I remove the decimal part of JavaScript number?

JavascriptWeb DevelopmentFront End Technology

To remove the decimal part from a number, use the JavaScript Math.trunc() method. The method returns the integer part of a number by removing the decimal part.

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <p>Value:</p>
      <script>
         var myFloat = 4.5;
         var myTrunc = Math.trunc( myFloat );
         document.write(myTrunc+ " ");
      </script>
   </body>
</html>

Output

Value:
4
raja
Published on 03-Feb-2018 13:11:38
Advertisements