ceil

(PHP 4, PHP 5)

ceilRound fractions up

Description

float ceil ( float $value )

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

Parameters

value

The value to round

Return Values

value rounded up to the next highest integer. The return value of ceil() is still of type float as the value range of float is usually bigger than that of integer.

Examples

Example #1 ceil() example

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

See Also

Коментарии

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)
 
function round_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
 
function round_out ($value$places=0) {
  if (
$places 0) { $places 0; }
 
$mult pow(10$places);
  return (
$value >= ceil($value $mult):floor($value $mult)) / $mult;
 }

 echo 
round_up (56.770012); // displays 56.78
 
echo round_up (-0.4530014); // displays -0.453
 
echo round_out (56.770012); // displays 56.78
 
echo round_out (-0.4530014); // displays -0.4531
?>
2005-02-28 14:40:48
http://php5.kiev.ua/manual/ru/function.ceil.html
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(01000);     // 0
echo ceiling(11);        // 1000
echo ceiling(10011000);  // 2000
echo ceiling(1.270.05);  // 1.30

?>
2008-08-29 13:46:51
http://php5.kiev.ua/manual/ru/function.ceil.html
Автор:
Actual behaviour:
echo ceil(-0.1); //result "-0" but i expect "0"

Workaround:
echo ceil(-0.1)+0; //result "0"
2011-05-10 06:12:44
http://php5.kiev.ua/manual/ru/function.ceil.html
Please see language.types.float for information regarding floating point precision issues.
2012-02-06 04:38:10
http://php5.kiev.ua/manual/ru/function.ceil.html
Caution!
<?php
$value 
77.4;
echo 
ceil($value 100) / 100;         // 77.41 - WRONG!
echo ceil(round($value 100)) / 100// 77.4 - OK!
2018-05-13 13:09:24
http://php5.kiev.ua/manual/ru/function.ceil.html

    Поддержать сайт на родительском проекте КГБ