Movatterモバイル変換


[0]ホーム

URL:


    cos »
    « bindec

    ceil

    (PHP 4, PHP 5, PHP 7, PHP 8)

    ceilRound fractions up

    Description

    ceil(int|float$num):float

    Returns the next highest integer value by rounding upnum if necessary.

    Parameters

    num

    The value to round

    Return Values

    num rounded up to the next highest integer. The return value ofceil() is still of typefloat as the value range offloat is usually bigger than that ofint.

    Changelog

    VersionDescription
    8.0.0num no longer accepts internal objects which support numeric conversion.

    Examples

    Example #1ceil() example

    <?php
    echoceil(4.3);// 5
    echoceil(9.999);// 10
    echoceil(-3.14);// -3
    ?>

    See Also

    Found A Problem?

    Learn How To Improve This PageSubmit a Pull RequestReport a Bug
    add a note

    User Contributed Notes5 notes

    Scott Weaver / scottmweaver * gmail
    16 years ago
    I needed this and couldn't find it so I thought someone else wouldn't have to look through a bunch of Google results-

    <?php

    // duplicates m$ excel's ceiling function
    if( !function_exists('ceiling') )
    {
    function
    ceiling($number,$significance=1)
    {
    return (
    is_numeric($number) &&is_numeric($significance) ) ? (ceil($number/$significance)*$significance) :false;
    }
    }

    echo
    ceiling(0,1000);// 0
    echoceiling(1,1);// 1000
    echoceiling(1001,1000);// 2000
    echoceiling(1.27,0.05);// 1.30

    ?>
    eep2004 at ukr dot net
    6 years ago
    Caution!
    <?php
    $value
    =77.4;
    echo
    ceil($value*100) /100;// 77.41 - WRONG!
    echoceil(round($value*100)) /100;// 77.4 - OK!
    steve_phpnet // nanovox \\ com
    20 years ago
    I couldn't find any functions to do what ceiling does while still leaving I specified number of decimal places, so I wrote a couple functions myself. round_up is like ceil but allows you to specify a number of decimal places. round_out does the same, but rounds away from zero.

    <?php
    // round_up:
    // rounds up a float to a specified number of decimal places
    // (basically acts like ceil() but allows for decimal places)
    functionround_up($value,$places=0) {
    if (
    $places<0) {$places=0; }
    $mult=pow(10,$places);
    return
    ceil($value*$mult) /$mult;
    }

    // round_out:
    // rounds a float away from zero to a specified number of decimal places
    functionround_out($value,$places=0) {
    if (
    $places<0) {$places=0; }
    $mult=pow(10,$places);
    return (
    $value>=0?ceil($value*$mult):floor($value*$mult)) /$mult;
    }

    echo
    round_up(56.77001,2);// displays 56.78
    echoround_up(-0.453001,4);// displays -0.453
    echoround_out(56.77001,2);// displays 56.78
    echoround_out(-0.453001,4);// displays -0.4531
    ?>
    oktam
    13 years ago
    Actual behaviour:
    echo ceil(-0.1); //result "-0" but i expect "0"

    Workaround:
    echo ceil(-0.1)+0; //result "0"
    frozenfire at php dot net
    13 years ago
    Please seehttp://www.php.net/manual/en/language.types.float.php for information regarding floating point precision issues.
    add a note
    To Top
    and to navigate •Enter to select •Esc to close
    PressEnter without selection to search using Google

    [8]ページ先頭

    ©2009-2025 Movatter.jp