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

How to round up a number in JavaScript?


The Math.ceil() method rounds a number upward to the nearest integer.

Example

You can try to the following code to round up a number −

Live Demo

<html>
   <head>
      <title>JavaScript Math ceil() Method</title>
   </head>
   <body>
      <script>
        var value = Math.ceil( 2.7 );
        document.write("First Test Value : " + value );

        var value = Math.ceil( 30.2 );
        document.write("<br />Second Test Value : " + value );
      </script>
   </body>
</html>

Output

First Test Value : 3
Second Test Value : 31