CKTIS / PHP
ceil()
Die Funktion ceil rundet zur positiven Unendlichkeit auf den kleinsten ganzzahligen Wert, der mindestens so groß wie die Eingabe ist.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
ceil(int|float $num): floatDie Funktion ceil rundet zur positiven Unendlichkeit auf den kleinsten ganzzahligen Wert, der mindestens so groß wie die Eingabe ist. Das Ergebnis ist auch bei int ein float. Nur als float exakt darstellbare int-Werte bleiben erhalten. Auf 64-Bit-Systemen wird aus 9007199254740993 der Wert 9007199254740992. Eine Gleitkommaabweichung knapp über einer ganzen Zahl kann das Ergebnis um eins erhöhen.
Signatur
ceil(int|float $num): float
Ausgabe des Beispiels
[3,"float"]
[-2,"float"]
[3,"float"]
[2,"float"]
9007199254740992
Beispiele
<?php
foreach ([2.01, -2.99, 3, 1.0000000000000002] as $x) {
$r = ceil($x);
echo json_encode([$r, get_debug_type($r)]), PHP_EOL;
}
if (PHP_INT_SIZE === 8) { printf("%.0f", ceil(9007199254740993)); }
Ergebnis
[3,"float"] [-2,"float"] [3,"float"] [2,"float"] 9007199254740992