Home >>JavaScript Math Reference >JavaScript ceil() Method

JavaScript ceil() Method

JavaScript ceil() Method

JavaScript ceil() method is used to round a given input number UPWARDS to the nearest integer and returns the result value. It accepts only a single parameter that is the given number to be rounded.

Syntax:
Math.ceil(x)

Parameter Values

Parameter Description
x This is a required parameter. It defines the number to be rounded.

Browser Support

Method Chrome Edge Firefox Safari Opera
ceil() Yes Yes Yes Yes Yes
Here is an example of JavaScript ceil() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = Math.ceil(22.2);
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
function myFunction1() {
  document.getElementById("demo1").innerHTML = Math.ceil(33.77);
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads