JavaScript ceil() method

Definition and usage

ceil() The method rounds the number up to the nearest integer and returns the result.

If the passed parameter is an integer, the value will not be rounded.

Description

ceil() The method performs a rounding up calculation and returns an integer that is greater than or equal to the function parameter and closest to it.

Instance

Example 1

Round a number up to its nearest integer :

Math.ceil(1.4)

Try it yourself

Example 2

Use the ceil() method for 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);

The results of a, b, c, d, e, and f will be :

1
1
5
6
-5
-5

Try it yourself

Syntax

Math.ceil(x)

Parameter value

Parameter Description
x Required. The number you want to round up.

Technical details

Return value : A number that represents the nearest integer when rounding up.
JavaScript version : ECMAScript 1

Prise en charge du navigateur

Math.ceil() C'est une fonctionnalité ES1 (JavaScript 1999). Tous les navigateurs le supportent pleinement :

Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support

Pages associées

Tutoriel :Mathématiques JavaScript