How to display Currency in Indian Numbering Format

2019-01-08 17:10发布

I have a question about formatting the Rupee currency (Indian Rupee - INR).

For example, numbers here are represented as:

1
10
100
1,000
10,000
1,00,000
10,00,000
1,00,00,000
10,00,00,000

Refer Indian Numbering System

I have to do with it PHP.

I have saw this question Displaying Currency in Indian Numbering Format. But couldn't able to get it for PHP my problem.

Update:

How to use money_format() in indian currency format?

20条回答
\"骚年 ilove
2楼-- · 2019-01-08 17:54
echo 'Rs. '.IND_money_format(1234567890);

function IND_money_format($money){
    $len = strlen($money);
    $m = '';
    $money = strrev($money);
    for($i=0;$i<$len;$i++){
        if(( $i==3 || ($i>3 && ($i-1)%2==0) )&& $i!=$len){
            $m .=',';
        }
        $m .=$money[$i];
    }
    return strrev($m);
}

NOTE:: it is not tested on float values and it suitable for only Integer

查看更多
看我几分像从前
3楼-- · 2019-01-08 17:54
$amount=-3000000000111.11;
$amount<0?(($sign='-').($amount*=-1)):$sign=''; //Extracting sign from given amount
$pos=strpos($amount, '.'); //Identifying the decimal point position
$amt=  substr($amount, $pos-3); // Extracting last 3 digits of integer part along with fractional part
$amount=  substr($amount,0, $pos-3); //removing the extracted part from amount
for(;strlen($amount);$amount=substr($amount,0,-2)) // Now loop through each 2 digits of remaining integer part
    $amt=substr ($amount,-2).','.$amt; //forming Indian Currency format by appending (,) for each 2 digits
echo $sign.$amt; //Appending sign
查看更多
Root(大扎)
4楼-- · 2019-01-08 17:57
declare @Price decimal(26,7)
Set @Price=1234456677
select FORMAT(@Price,  'c', 'en-In')

Result:

1,23,44,56,677.00
查看更多
家丑人穷心不美
5楼-- · 2019-01-08 17:58

I have used different format parameters to money_format() for my output.

setlocale(LC_MONETARY, 'en_IN');
if (ctype_digit($amount) ) {
     // is whole number
     // if not required any numbers after decimal use this format 
     $amount = money_format('%!.0n', $amount);
}
else {
     // is not whole number
     $amount = money_format('%!i', $amount);
}
//$amount=10043445.7887 outputs 1,00,43,445.79
//$amount=10043445 outputs 1,00,43,445
查看更多
我想做一个坏孩纸
6楼-- · 2019-01-08 17:59

You should check the number_format function.Here is the link

Separating thousands with commas will look like

$rupias = number_format($number, 2, ',', ',');
查看更多
欢心
7楼-- · 2019-01-08 18:03

It's my very own function to do the task

function bd_money($num) {
    $pre = NULL; $sep = array(); $app = '00';
    $s=substr($num,0,1);
    if ($s=='-') {$pre= '-';$num = substr($num,1);}
    $num=explode('.',$num);
    if (count($num)>1) $app=$num[1];
    if (strlen($num[0])<4) return $pre . $num[0] . '.' . $app;
    $th=substr($num[0],-3);
    $hu=substr($num[0],0,-3);
    while(strlen($hu)>0){$sep[]=substr($hu,-2); $hu=substr($hu,0,-2);}
    return $pre.implode(',',array_reverse($sep)).','.$th.'.'.$app;
}

It took 0.0110 Seconds per THOUSAND query while number_format took 0.001 only. Always try to use PHP native functions only when performance is target issue.

查看更多
登录 后发表回答