首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在PHP中显示印度数字格式的货币?

如何在PHP中显示印度数字格式的货币?
EN

Stack Overflow用户
提问于 2012-04-06 18:51:42
回答 17查看 77.5K关注 0票数 34

我有一个关于格式化卢比货币(印度卢比-印度卢比)的问题。

例如,这里的数字表示为:

代码语言:javascript
运行
复制
1
10
100
1,000
10,000
1,00,000
10,00,000
1,00,00,000
10,00,00,000

参考Indian Numbering System

我不得不用PHP解决这个问题。

我已经看到了这个问题Displaying Currency in Indian Numbering Format。但是我的问题是不能在PHP中得到它。

更新:

如何在印度货币格式中使用money_format()

EN

回答 17

Stack Overflow用户

发布于 2019-02-09 14:56:15

代码语言:javascript
运行
复制
$num = 1234567890.123;

$num = preg_replace("/(\d+?)(?=(\d\d)+(\d)(?!\d))(\.\d+)?/i", "$1,", $num);

echo $num;

// Input : 1234567890.123

// Output : 1,23,45,67,890.123


// Input : -1234567890.123

// Output : -1,23,45,67,890.123
票数 22
EN

Stack Overflow用户

发布于 2014-02-16 03:23:01

检查这个代码,它工作100%的印度卢比格式与十进制格式。您可以使用如下数字:

123456.789 123.456 123.4 123和1,2,3,4,5,6,7,8,9,.222

代码语言:javascript
运行
复制
function moneyFormatIndia($num){

$explrestunits = "" ;
$num = preg_replace('/,+/', '', $num);
$words = explode(".", $num);
$des = "00";
if(count($words)<=2){
    $num=$words[0];
    if(count($words)>=2){$des=$words[1];}
    if(strlen($des)<2){$des="$des";}else{$des=substr($des,0,2);}
}
if(strlen($num)>3){
    $lastthree = substr($num, strlen($num)-3, strlen($num));
    $restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits
    $restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping.
    $expunit = str_split($restunits, 2);
    for($i=0; $i<sizeof($expunit); $i++){
        // creates each of the 2's group and adds a comma to the end
        if($i==0)
        {
            $explrestunits .= (int)$expunit[$i].","; // if is first value , convert into integer
        }else{
            $explrestunits .= $expunit[$i].",";
        }
    }
    $thecash = $explrestunits.$lastthree;
} else {
    $thecash = $num;
}
return "$thecash.$des"; // writes the final format where $currency is the currency symbol.

}
票数 5
EN

Stack Overflow用户

发布于 2018-09-21 13:23:14

只需使用下面的函数来格式化INR。

代码语言:javascript
运行
复制
function amount_inr_format($amount) {
    $fmt = new \NumberFormatter($locale = 'en_IN', NumberFormatter::DECIMAL);
    return $fmt->format($amount);
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10042485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档