View Full Version : number changing to higher integer
auriaks
11-30-2009, 06:34 PM
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, ask :) thanks
Schmoopy
11-30-2009, 09:15 PM
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:
<?php
$number = 1.2;
$number = ceil($number);
echo $number; // Ouputs 2
?>
Or if you mean the opposite:
<?php
$number = 1.8;
$number = floor($number);
echo $number; // Ouputs 1
?>
Or if you mean just rounding in general:
<?php
$number = 1.8;
$number = round($number);
echo $number; // Ouputs 2
?>
Hopefully one of the above is what you want. If not, just say.
auriaks
11-30-2009, 11:36 PM
thanks... first one fits my needs :)
auriaks
12-30-2009, 02:33 PM
i have trying to find command which makes number 33.333333333 to 33.33, but failed in english :confused: can someone help with this? it's like 2 numbers after point.
jscheuer1
12-30-2009, 03:12 PM
See:
http://php.net/manual/en/function.round.php
particularly:
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
?>
So I image you would want something like:
$number = round($number, 2, PHP_ROUND_HALF_DOWN);
or:
$number = round($number, 2);
perhaps even:
$number = 33.333333;
$number = ceil($number*100);
echo $number/100;
auriaks
12-30-2009, 03:41 PM
OK, thanks :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.