I would like to round the the lowest digit of this integer examples:
1940 > 1900
104942 > 104900
44947 > 44900
I was trying using :
round( 44947, -1 ) > 44950
round( 44945, -2 ) > 45000
Any ideas?
I would like to round the the lowest digit of this integer examples:
1940 > 1900
104942 > 104900
44947 > 44900
I was trying using :
round( 44947, -1 ) > 44950
round( 44945, -2 ) > 45000
Any ideas?
Use floor
echo floor(1940/100)*100;
Round will round it - so .6 becomes 1, floor rounds off, so .6 becomes 0.
So...
echo floor(1960/100)*100;
echo round(1960,-2);
will give 1900
and 2000
Unfortunately you can't use the same thing as round and specify a number of DP's, so the /100*100 does that job.
You have to round up to two digits to get the desired result, check this
$var=44947;
echo round($var,-2);
you can round up to any number.in this code as you mention round to floor up to range of 100
$num=44947;
$num=floor($num/100)*100;
var_dump($num);
round( 104942 , -2 , PHP_ROUND_HALF_DOWN);
http://php.net/manual/en/function.round.php
mode Use one of the following constants to specify the mode in which rounding occurs.