Math.ceil()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Die statische Methode Math.ceil() rundet immer auf und gibt die kleinste ganze Zahl zurück, die größer oder gleich einer gegebenen Zahl ist.

Probieren Sie es aus

console.log(Math.ceil(0.95));
// Expected output: 1

console.log(Math.ceil(4));
// Expected output: 4

console.log(Math.ceil(7.004));
// Expected output: 8

console.log(Math.ceil(-7.004));
// Expected output: -7

Syntax

js
Math.ceil(x)

Parameter

x

Eine Zahl.

Rückgabewert

Die kleinste ganze Zahl, die größer oder gleich x ist. Dies entspricht dem Wert von -Math.floor(-x).

Beschreibung

Da ceil() eine statische Methode von Math ist, wird sie immer als Math.ceil() verwendet und nicht als Methode eines selbst erstellten Math-Objekts (Math ist kein Konstruktor).

Beispiele

Verwendung von Math.ceil()

js
Math.ceil(-Infinity); // -Infinity
Math.ceil(-7.004); // -7
Math.ceil(-4); // -4
Math.ceil(-0.95); // -0
Math.ceil(-0); // -0
Math.ceil(0); // 0
Math.ceil(0.95); // 1
Math.ceil(4); // 4
Math.ceil(7.004); // 8
Math.ceil(Infinity); // Infinity

Spezifikationen

Specification
ECMAScript® 2025 Language Specification
# sec-math.ceil

Browser-Kompatibilität

BCD tables only load in the browser

Siehe auch