Special number function


#1

Is there any function out there or someone can create a function that will strip numbers from 10 to 10 or 100 to 100 and replace them with something else ? I mean if the value is from 30 to 39 should be replaced as 30+ and so on…
I’m looking for a function to replace my current way of viewing some stats on my articles. Im currently using the default " . number_format($variable) . "


#2

You could just do something like this, optionally wrap it in a function somewhere for easier reuse

[php]echo floor($number/10)*10 . ‘+’;[/php]


#3

I’ve tried this and always i get 0+ as result


#4

Which numbers did you try?

[php]$numbers = [10, 15, 22, 26, 35];

foreach($numbers as $number) {
var_dump(floor($number/10)*10 . ‘+’);
}[/php]

string(3) "10+" string(3) "10+" string(3) "20+" string(3) "20+" string(3) "30+"

note: changed ceil to floor to get your desired result. Either way shouldn’t give you 0+ all the time though