function kmb($count, $precision = 2) {
if ($count < 1000000) {
// Anything less than a million
$n_format = number_format($count / 1000) . 'K';
} else if ($count < 1000000000) {
// Anything less than a billion
$n_format = number_format($count / 1000000, $precision) . 'M';
} else {
// At least a billion
$n_format = number_format($count / 1000000000, $precision) . 'B';
}
return $n_format;
}
echo kmb(272937);
> 273K
echo kmb(2729347);
> 2.73M
echo kmb(2729347874);
> 2.73B