📜  把长号码缩短到九巴? - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:15.742000             🧑  作者: Mango

代码示例1
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