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
function number_abbr($number)
{
$abbrevs = [12 => 'T', 9 => 'B', 6 => 'M', 3 => 'K', 0 => ''];
foreach ($abbrevs as $exponent => $abbrev) {
if (abs($number) >= pow(10, $exponent)) {
$display = $number / pow(10, $exponent);
$decimals = ($exponent >= 3 && round($display) < 100) ? 1 : 0;
$number = number_format($display, $decimals).$abbrev;
break;
}
}
return $number;
}
Works for positives and negatives.