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

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 16-Feb-2018 11:25:19
Advertisements