JavaScript ceil() method
- Föregående sida cbrt()
- Nästa sida clz32()
- Gå tillbaka till föregående nivå JavaScript Math referens 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 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)
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 |
Webbläsarstöd
Math.ceil()
Är ES1-funktioner (JavaScript 1999). Alla webbläsare stöder det fullt ut:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Stöd | Stöd | Stöd | Stöd | Stöd | Stöd |
Relaterade sidor
Lär dig:JavaScript matematik
- Föregående sida cbrt()
- Nästa sida clz32()
- Gå tillbaka till föregående nivå JavaScript Math referens manual