Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript ceil() Method

JavaScript ceil() Method

Math Object Reference JavaScript Math object

Example

Round a number up:

Math.ceil(1.4)

Output result:

2

Try it »


Definition and Usage

The ceil() method rounds a number up.

If the argument is an integer, the value remains unchanged.

**Note:** The ceil() method performs an upward rounding calculation and returns the integer that is greater than or equal to the function argument and closest to it.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the ceil() method


Syntax

Math.ceil(

x

)

Parameter value

Parameters Description
x Required. Must be a numeric value.

Return Value

Type Description
Number The integer that is greater than or equal to x and closest to it.

Technical Details

JavaScript version: 1.0

More examples

Example

In this example, we will apply the ceil() method to different numbers:

var a=Math.ceil(0.60);

var b=Math.ceil(0.40);

var c=Math.ceil(5);

var d=Math.ceil(5.1);

var e=Math.ceil(-5.1);

var f=Math.ceil(-5.9);

Output of a, b, c, d, e, and f:

1

1

5

6

-5

-5

Try it »


Math Object Reference JavaScript Math object