|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
ceil (PHP 3, PHP 4, PHP 5) ceil -- Zaokrągla ułamki w górę Opisfloat ceil ( float liczba )
Zwraca nabliższą liczbę całkowitą, większą lub równą podanemu argumentowi
liczba.
Zwracana przez funkcję ceil() wartość jest nadal typu
float gdyż zakres tego typu jest zwykle większy niż zakres
typu integer.
Przykład 1. przykład ceil() |
echo ceil(4.3); // 5;
echo ceil(9.999); // 10;
|
|
Patrz także: floor() i
round().
User Contributed Notesermolaeva_elena at mail dot ru
20-Dec-2005 04:27
To round a number up to the nearest power of 10,
I've used
= ceil(intval($val)/10)*10;
nobody
23-Nov-2005 06:00
Here's a more simple one to do ceil to nearest 10:
function ceilpow10(val) {
if (val % 10 == 0) return val;
return val + (10 - (val % 10));
}
schmad at miller dash group dot net
19-Apr-2005 06:38
To round a number up to the nearest power of 10 use this simple procedure:
$multiplier = .1;
while($number>1)
{
$number /= 10;
$multiplier *= 10;
}
$number = ceil($number) * $multiplier;
coxswain at navaldomination dot com
16-Mar-2005 11:06
steve_phpnet // nanovox \\ com wouldn't:
<?php
$ceil = ceil(4.67 * 10) / 10;
?>
work just as well?
steve_phpnet // nanovox \\ com
28-Feb-2005 09:40
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
function round_up ($value, $places=0) {
if ($places < 0) { $places = 0; }
$mult = pow(10, $places);
return ceil($value * $mult) / $mult;
}
function round_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); echo round_up (-0.453001, 4); echo round_out (56.77001, 2); echo round_out (-0.453001, 4); ?>
sven at plus dot hr
10-Feb-2005 12:59
function roundaway($num) {
switch($num) {
case ($num > 0):
$n = ceil($num);
break;
case ($num < 0):
$n = floor($num);
break;
case ($num == 0):
$n = 0;
break;
}
return $n;
}
aaron at mind-design dot co dot uk
21-Jul-2004 10:10
Or for the terniary fans:
<?php
function roundaway($num) {
return(($num > 0) ? ceil($num) : floor($num));
}
?>
Slightly pointless, but there you have it, in one line only..
rainfalling at yahoo dot com
22-Apr-2004 02:51
IceKarma said: "If you want, say, 2.6 to round to 3, and -2.6 to round to -3, you want round(), which rounds away from zero."
That's not always true. round() doesn't work that way, like zomis2k said it just rounds up _or_ down to the nearest non-decimal number. However this should work.
<?php
function roundaway($num) {
if ($num > 0)
return ceil($num);
elseif ($num < 0)
return floor($num);
elseif ($num == 0)
return 0;
}
?>
roger_dupere at hotmail dot com
10-Nov-2003 11:02
Here is a navbar using the ceil function.
<?php
function navbar($num_rows,$page,$link) {
$nbrlink = 10; $page = (int) $page; $num_rows = (int) $num_rows;
if( $num_rows > 0 ) {
$total_page = ceil( $num_rows / $nbrlink );
for( $i=1;$i<$total_page+1;$i++ ) {
if( $i == $page ) {
$ret .= " <b>$i</b> ";
} else {
if( strstr( $link,"?" ) ) {
$ret .= " <a href=\"$link&page=$i\">$i</a> ";
} else {
$ret .= " <a href=\"$link?page=$i\">$i</a> ";
}
}
}
return $ret;
}
}
$navbar = navbar( $num_rows, $page, "listmovie.php?id=$id" );
if( $navbar != null || $navbar != "" ) {
print( "<p><div align=\"center\">$navbar</div></p>" );
}
?>
zomis2k at hotmail dot com
22-May-2003 08:24
>If you want, say, 2.6 to round to 3, and -2.6 to round to -3, you want round(), which rounds away from zero.
round() does not always round away from zero
round(2.4) = 2
round(2.6) = 3
round(-2.4) = -2
round(-2.6) = -3
round() rounds number to nearest non-decimal number.
IceKarma
22-Apr-2003 02:31
ceil() rounds towards positive infinity ("up"), floor() rounds towards negative infinity ("down").
If you want, say, 2.6 to round to 3, and -2.6 to round to -3, you want round(), which rounds away from zero.
clx at deim dot net
11-Jun-2002 10:55
<?php
echo ceil(2.6); echo ceil(-2.6); ?>
|