印度货币的 PHP 货币格式?

发布于 2024-12-21 13:23:58 字数 88 浏览 2 评论 0原文

例如 $num='7,57,800';

如何将 $number 的值显示为 75.7 万卢比?

For example $num='7,57,800';

How can I display the value of $number as 7.57 Lakhs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

高速公鹿 2024-12-28 13:23:58

这是函数:

function formatInIndianStyle($num){
     $pos = strpos((string)$num, ".");
     if ($pos === false) {
        $decimalpart="00";
     }
     if (!($pos === false)) {
        $decimalpart= substr($num, $pos+1, 2); $num = substr($num,0,$pos);
     }

     if(strlen($num)>3 & strlen($num) <= 12){
         $last3digits = substr($num, -3 );
         $numexceptlastdigits = substr($num, 0, -3 );
         $formatted = makeComma($numexceptlastdigits);
         $stringtoreturn = $formatted.",".$last3digits.".".$decimalpart ;
     }elseif(strlen($num)<=3){
        $stringtoreturn = $num.".".$decimalpart ;
     }elseif(strlen($num)>12){
        $stringtoreturn = number_format($num, 2);
     }

     if(substr($stringtoreturn,0,2)=="-,"){
        $stringtoreturn = "-".substr($stringtoreturn,2 );
     }

     return $stringtoreturn;
 }

 function makeComma($input){ 
     if(strlen($input)<=2)
     { return $input; }
     $length=substr($input,0,strlen($input)-2);
     $formatted_input = makeComma($length).",".substr($input,-2);
     return $formatted_input;
 }

Here's the function:

function formatInIndianStyle($num){
     $pos = strpos((string)$num, ".");
     if ($pos === false) {
        $decimalpart="00";
     }
     if (!($pos === false)) {
        $decimalpart= substr($num, $pos+1, 2); $num = substr($num,0,$pos);
     }

     if(strlen($num)>3 & strlen($num) <= 12){
         $last3digits = substr($num, -3 );
         $numexceptlastdigits = substr($num, 0, -3 );
         $formatted = makeComma($numexceptlastdigits);
         $stringtoreturn = $formatted.",".$last3digits.".".$decimalpart ;
     }elseif(strlen($num)<=3){
        $stringtoreturn = $num.".".$decimalpart ;
     }elseif(strlen($num)>12){
        $stringtoreturn = number_format($num, 2);
     }

     if(substr($stringtoreturn,0,2)=="-,"){
        $stringtoreturn = "-".substr($stringtoreturn,2 );
     }

     return $stringtoreturn;
 }

 function makeComma($input){ 
     if(strlen($input)<=2)
     { return $input; }
     $length=substr($input,0,strlen($input)-2);
     $formatted_input = makeComma($length).",".substr($input,-2);
     return $formatted_input;
 }
彩虹直至黑白 2024-12-28 13:23:58

检查这个插件 - http://archive.plugins.jquery.com/project/numberformatter

这是如何使用此插件的示例。

 $("#salary").blur(function(){
 $(this).parseNumber({format:"#,###.00", locale:"us"});
$(this).formatNumber({format:"#,###.00", locale:"us"});
});

只需更改区域设置即可。

有关更多示例和信息,请访问 - http://code.google.com /p/jquery-numberformatter/

我的示例来源:http://code.google.com/p/jquery-numberformatter/

希望这有帮助:)

Check this plugin- http://archive.plugins.jquery.com/project/numberformatter

Here's an example of how you'd use this plugin.

 $("#salary").blur(function(){
 $(this).parseNumber({format:"#,###.00", locale:"us"});
$(this).formatNumber({format:"#,###.00", locale:"us"});
});

Just change the locale..

For more example and information visit- http://code.google.com/p/jquery-numberformatter/

My example source: http://code.google.com/p/jquery-numberformatter/

Hope this helps :)

郁金香雨 2024-12-28 13:23:58

这里还有一个解决方案,仅供参考:

<?php
#    Output easy-to-read numbers
#    by james at bandit.co.nz
function bd_nice_number($n) {
    // first strip any formatting;
    $n = (0+str_replace(",","",$n));

    // is this a number?
    if(!is_numeric($n)) return false;

    // now filter it;
    if($n>1000000000000) return round(($n/1000000000000),1).' trillion';
    else if($n>1000000000) return round(($n/1000000000),1).' billion';
    else if($n>1000000) return round(($n/1000000),1).' million';
    else if($n>1000) return round(($n/1000),1).' thousand';

    return number_format($n);
}
?>

Here is another solution just for reference:

<?php
#    Output easy-to-read numbers
#    by james at bandit.co.nz
function bd_nice_number($n) {
    // first strip any formatting;
    $n = (0+str_replace(",","",$n));

    // is this a number?
    if(!is_numeric($n)) return false;

    // now filter it;
    if($n>1000000000000) return round(($n/1000000000000),1).' trillion';
    else if($n>1000000000) return round(($n/1000000000),1).' billion';
    else if($n>1000000) return round(($n/1000000),1).' million';
    else if($n>1000) return round(($n/1000),1).' thousand';

    return number_format($n);
}
?>
惜醉颜 2024-12-28 13:23:58
<?php //Credits are going to: @Niet-the-Dark-Absol

    function indian_number_format($num){
        $num=explode('.',$num);
        $dec=(count($num)==2)?'.'.$num[1]:'.00';
        $num = (string)$num[0];
        if( strlen($num) < 4) return $num;
        $tail = substr($num,-3);
        $head = substr($num,0,-3);
        $head = preg_replace("/\B(?=(?:\d{2})+(?!\d))/",",",$head);
        return $head.",".$tail.$dec;
    }
?>

问题:stackoverflow.com/questions/10042485

<?php //Credits are going to: @Niet-the-Dark-Absol

    function indian_number_format($num){
        $num=explode('.',$num);
        $dec=(count($num)==2)?'.'.$num[1]:'.00';
        $num = (string)$num[0];
        if( strlen($num) < 4) return $num;
        $tail = substr($num,-3);
        $head = substr($num,0,-3);
        $head = preg_replace("/\B(?=(?:\d{2})+(?!\d))/",",",$head);
        return $head.",".$tail.$dec;
    }
?>

Question: stackoverflow.com/questions/10042485

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文