基于 PHP 印度语的短数字格式

Short Number format in PHP Indian Based

Google 在 PHP 中搜索 短数字格式,从 Whosebug、Github 等获得了数千个工作结果,但我没有得到印度格式.

的任何结果

例如:

在其他国家:1000 等于 1k,100000 等于 100k10000000等于 10m

但在印度:1000 相当于 1k OR 1T,100000 相当于 1L10000000 相当于 1c

有人可以帮我做吗?

借助这个answer

我想出了一个解决方案给你:

<?php
function indian_short_number($n) {
    if($n <= 99999){
    $precision = 3;
    if ($n < 1000) {
        // Anything less than a thousand
        $n_format = number_format($n);
    } else {
        // At least a thousand
        $n_format = number_format($n / 1000, $precision) . ' K';
    }
/* Use this code if you want to round off your results
$n_format = ceil($n_format / 10) * 10;
if($n >= 1000){ 
$n_format = $n_format . ' K';
}
*/
    return $n_format;   
    }
    else{
    $precision = 2;
    if ($n > 99999 && $n < 9999999) {
        // Anything more than a Lac and less than crore
        $n_format = number_format($n / 100000, $precision) . ' L';
    } elseif ($n > 999999) {
        // At least a crore
        $n_format = number_format($n / 10000000, $precision) . ' C';
    }
/* Use this code if you want to round off your results
$n_format = ceil($n_format / 10) * 10;
if($n >= 10000 && $n < 10000000){ 
$n_format = $n_format . ' L';
}
elseif($n >= 1000000){ 
$n_format = $n_format . ' C';
}
*/
    return $n_format;
}
}
echo indian_short_number(10000);
?>

四舍五入的代码不正确。 (对于 18100,它四舍五入为 20 K 而不是 19 K

如果有任何访问者编辑答案并修复它,我将不胜感激。

希望对你有帮助。