JavaScript Tutorial JavaScript References

JavaScript - Math.ceil() Method



The JavaScript Math.ceil() method returns the next highest integer value by rounding up the specified number, if necessary. In other words, it rounds the fraction UP of the given number.

Syntax

Math.ceil(x)

Parameters

x Specify a number.

Return Value

Returns the next highest integer value by rounding UP the specified number, if necessary.

Example:

In the example below, Math.ceil() method is used to round the fraction UP of the specified number.

var txt;

txt = "Math.ceil(10.5) = " + Math.ceil(10.5) + "<br>";
txt = txt + "Math.ceil(-10.5) = " + Math.ceil(-10.5) + "<br>";
txt = txt + "Math.ceil(0.5) = " + Math.ceil(0.5) + "<br>";
txt = txt + "Math.ceil(-0.5) = " + Math.ceil(-0.5) + "<br>";

The output (value of txt) after running above script will be:

Math.ceil(10.5) = 11
Math.ceil(-10.5) = -10
Math.ceil(0.5) = 1
Math.ceil(-0.5) = 0

❮ JavaScript - Math Object

5