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
  • 301
  • 1
  • 6
  • 26

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
  • 56,122
  • 11
  • 43
  • 55
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,846
  • 4
  • 34
  • 70
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,600
  • 17
  • 23
-2

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

Eagle
  • 22
  • 3