JavaScript ceil() method
- Forrige side cbrt()
- Næste side clz32()
- Gå tilbage til niveauet over JavaScript Math Reference Manual
Definition and usage
ceil()
The method rounds a 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 ceiling calculation and returns the integer that is greater than or equal to the function parameter and closest to it.
Example
Example 1
Round a number up to its nearest integer:
Math.ceil(1.4)
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 for a, b, c, d, e, and f will be:
1 1 5 6 -5 -5
Syntax
Math.ceil(x)
Parameter value
Parameter | Description |
---|---|
x | Required. The number you want to round up. |
Technical details
Return value: | A number, representing the nearest integer when rounding up. |
---|---|
JavaScript version: | ECMAScript 1 |
Browserstøtte
Math.ceil()
Er ES1 funktion (JavaScript 1999). Alle browsere understøtter det fuldt ud:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Support | Support | Support | Support | Support | Support |
Relaterede sider
Tutorial:JavaScript matematik
- Forrige side cbrt()
- Næste side clz32()
- Gå tilbage til niveauet over JavaScript Math Reference Manual