📅  最后修改于: 2022-03-11 14:54:15.742000             🧑  作者: Mango
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