0

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?

Igor O
  • 299
  • 6
  • 24

5 Answers5

1

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.

Nigel Ren
  • 53,991
  • 11
  • 38
  • 52
0

You have to round up to two digits to get the desired result, check this

$var=44947;
echo round($var,-2);
RAUSHAN KUMAR
  • 5,595
  • 4
  • 31
  • 65
0

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);
Piyush Kumar
  • 48
  • 1
  • 4
0
 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.

iwaduarte
  • 1,258
  • 19
  • 20
-2

Wouldn't round(x/100)*100 do the trick?

Eagle
  • 22
  • 3