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

How to get the smallest integer greater than or equal to a number in JavaScript?


To get the smallest integer greater than or equal to a number, use the JavaScript Math.ceil() method. This method returns the smallest integer greater than or equal to a number.

Example

You can try to run the following code to get the smallest integer greater than or equal to a number −

<html>
   <head>
      <title>JavaScript Math ceil() Method</title>
   </head>
   <body>
      <script>
         var value = Math.ceil(80.55);
         document.write("First Value : " + value );
         
         value = Math.ceil(42.45);
         document.write("<br />Second Value : " + value );
         
         value = Math.ceil(-70.70);
         document.write("<br />Third Value : " + value );
         
         value = Math.ceil(-20.30);
         document.write("<br />Fourth Value : " + value );
      </script>
   </body>
</html>