-3

What I'm trying to do seems rather simple, but I can't get it to work with the php.net documentation..

Numbers should always be rounded to "tens"

So:

1 -> 10

7 -> 10

12 -> 20

18 -> 20

23 -> 30

35 -> 40

Kevinster
  • 67
  • 1
  • 2
  • 9

3 Answers3

1

Something like this should work:

$rounded_num = round($orig_num / 10) * 10;
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

Just read documentation about round.

round($number, -1);
Gustek
  • 3,680
  • 2
  • 22
  • 36
  • **"but I can't get it to work with the php.net documentation"** Plus, haven't been able to access the damn php.net because of a malware notification. – Kevinster Oct 24 '13 at 13:46
0

Your should use round() function. But if you want manual way, you can use something like that:

$number = 189;
$length = strlen((string)$number);
$div = '1';
for ($i=0;$i<$length-1;$i++){
$div .= '0';
}
$result = (int)$div*(ceil($number/$div));

$result = 200

AxelPAL
  • 1,047
  • 3
  • 12
  • 19