Latest web development tutorials

JavaScript ceil () method

Math Object Reference JavaScript Math Object

Examples

On a number rounded up:

Math.ceil(1.4)

Output:

2

try it"

Definition and Usage

ceil () method on a number rounded up.

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

Note: ceil () method to perform the calculation is rounded up, it returns greater than or equal to the function parameters, and its nearest integer.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support ceil () method


grammar

Math.ceil( x )

Parameter Value

参数 描述
x 必需。必须是一个数值。

return value

类型 描述
Number 大于等于 x,并且与它最接近的整数。

technical details

JavaScript version: 1.0


More examples

Examples

In this case, we will ceil () method applied 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"


Math Object Reference JavaScript Math Object