JavaScript ceil()Method

Math 对象参考手册JavaScript Math Object

Examples

Round a number upward:

Math.ceil(1.4)

Output:

2

Try it yourself »

Definition and Usage

The ceil() method rounds a number upward.

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

Note:The ceil() method rounds up and returns the nearest integer greater than or equal to the argument.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the ceil() method


Syntax

Math.ceil(x)

Parameter Values

Parameter Description
x Required. Must be a number.

Return Value

Type Description
Number An integer greater than or equal to x, and closest to it.

Technical Details

JavaScript Version: 1.0


More Examples

Examples

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);

a, b, c, d, e, and f output:

1
1
5
6
-5
-5

Try it yourself »


Math 对象参考手册JavaScript Math Object

Other Extensions