I\'ve googled this a lot but i can\'t find any helpful functions based on my queries.
What i want is:
100 -> 100
1000 -> 1,000
142840 -> 142
Altough this question was asked quite some time ago I have a different solution, which I think is even more simple:
function shorten($number){
$suffix = ["", "K", "M", "B"];
$precision = 1;
for($i = 0; $i < count($suffix); $i++){
$divide = $number / pow(1000, $i);
if($divide < 1000){
return round($divide, $precision).$suffix[$i];
break;
}
}
}
echo shorten(1000);
I hope that it's still helpful for someone.