Categories
Web development

JavaScript Math.ceil()

JavaScript Math.ceil()

The JavaScript Math.ceil() rounds a number upwards to the nearest integer, and returns the result.

Syntax:

Math.ceil(number)

Example:

<!DOCTYPE html>
<html>
<body>

<button onclick="ceilExample()">Try it</button>
<p id="math-ceil"></p>

<script>
function ceilExample() {
  document.getElementById("math-ceil").innerHTML = Math.ceil(2.2);
}
</script>

</body>
</html>

Output:

Click the button to round the number 2.2 upward to its nearest integer.


Enjoy coding!

Read also:

JavaScript Math Object

JavaScript Math.cbrt()

JavaScript Math.fround()