hi there,
I know that is possible to make numbers 1.3 to convert to ~1 (2.6 ~ 3 etc...)
But is it possible to change them to higher side when they are 1.1 ; 1.2; 1.3, 5.1, They would be like 1; 1; 1; 5;
If you need more specific details, askthanks
hi there,
I know that is possible to make numbers 1.3 to convert to ~1 (2.6 ~ 3 etc...)
But is it possible to change them to higher side when they are 1.1 ; 1.2; 1.3, 5.1, They would be like 1; 1; 1; 5;
If you need more specific details, askthanks
Looks like you contradicted yourself. You said "higher side", but then you rounded them down, do you mean:
If you have 1.2 it will go to 2?
If so, handy function:
Or if you mean the opposite:PHP Code:<?php
$number = 1.2;
$number = ceil($number);
echo $number; // Ouputs 2
?>
Or if you mean just rounding in general:PHP Code:<?php
$number = 1.8;
$number = floor($number);
echo $number; // Ouputs 1
?>
Hopefully one of the above is what you want. If not, just say.PHP Code:<?php
$number = 1.8;
$number = round($number);
echo $number; // Ouputs 2
?>
thanks... first one fits my needs![]()
i have trying to find command which makes number 33.333333333 to 33.33, but failed in englishcan someone help with this? it's like 2 numbers after point.
See:
http://php.net/manual/en/function.round.php
particularly:
So I image you would want something like:Example #1 round() examples
<?php
echo round(3.4); // 3
echo round(3.5); // 4
echo round(3.6); // 4
echo round(3.6, 0); // 4
echo round(1.95583, 2); // 1.96
echo round(1241757, -3); // 1242000
echo round(5.045, 2); // 5.05
echo round(5.055, 2); // 5.06
?>
Example #2 mode() examples
<?php
echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10
echo round(9.5, 0,PHP_ROUND_HALF_DOWN); // 9
echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10
echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9
echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9
echo round(8.5, 0,PHP_ROUND_HALF_DOWN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8
echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9
?>
or:Code:$number = round($number, 2, PHP_ROUND_HALF_DOWN);
perhaps even:Code:$number = round($number, 2);
Code:$number = 33.333333; $number = ceil($number*100); echo $number/100;
Last edited by jscheuer1; 12-30-2009 at 03:25 PM.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
OK, thanks![]()
Bookmarks