Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

ceil()

Use ceil to round toward positive infinity, producing the smallest integral value at least as large as the argument.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

ceil(int|float $num): float

Use ceil to round toward positive infinity, producing the smallest integral value at least as large as the argument. The result is a float even when the input is an int. A negative fraction rounds toward zero. Binary floating-point error in the input can push a value just above an intended integer. Only int values exactly representable as float retain their value. On 64-bit systems 9007199254740993 becomes 9007199254740992.

Signature

ceil(int|float $num): float

Example output

[3,"float"]
[-2,"float"]
[3,"float"]
[2,"float"]
9007199254740992

Examples

<?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)); }

Result

[3,"float"]
[-2,"float"]
[3,"float"]
[2,"float"]
9007199254740992

Sources