Skip to content

JavaScript Math ceil() | Method

  • by

JavaScript Math ceil() method is used to round a number rounded UP to the nearest integer. This is a static method. Hence, we are accessing the method using the class name, Math.

Math.ceil(number)

JavaScript Math ceil()

Simple example code.

<!DOCTYPE html>
<html>
<body>
  <script >
   console.log(Math.ceil(.95));

   console.log(Math.ceil(4));

   console.log(Math.ceil(7.004));

   console.log(Math.ceil(-7.004));
 </script>
</body>
</html>

Output:

JavaScript Math ceil Method

Math.ceil() with Numeric String

In this case, the numeric string is converted to a number.

let num = Math.ceil("2.490");
console.log(num); // 3

Non-Numeric Argument

let value = Math.ceil("JavaScript");
console.log(value);

Output: NaN

Do comment if you have any doubts or suggestions on this Js method topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading