/

HTML / CSS / JavaScript Tutorial

JavaScript Math method: ceil()

[this page | pdf | back links]

The ceil() method (of the Math object) rounds a real number towards positive infinity.

 

It has the following syntax with the following parameters:

 

Math.ceil(x)

 

Parameter

Required / Optional

Description

x

Required

Input parameter

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
var c = 4.3;
document.getElementById("Example").innerHTML =
  'var x = Math.ceil(' + c + ')';
document.getElementById("Result").innerHTML = Math.ceil(c);
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodMathCeil() {
  var z = 12.5; return !!Math.ceil(z);
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Numbers and Math


Desktop view | Switch to Mobile