Computer >> Computer tutorials >  >> Programming >> Javascript

How can I remove the decimal part of JavaScript number?


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

<!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