1

我正在尝试将数字转换为印度货币格式

100000 = 1,00,000

我有用

$explrestunits = "" ;
        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; // writes the final format where $currency is the currency symbol.

但是当我使用减号(-)10000(五位数)它返回输出0,10,000

它应该是-10,000 你知道吗..

4

1 回答 1

3

尝试这样的事情

<?php
$amount = '100000';
setlocale(LC_MONETARY, 'en_IN');
$amount = money_format('%!i', $amount);
$amount=explode('.',$amount); //Comment this if you want amount value to be 1,00,000.00
echo $amount[0]; //Comment this if you want amount value to be 1,00,000.00

输出:

1,00,000

编辑 :

但是当我使用减号 (-) 和 10000(五位数字)时,它返回输出 0,10,000

它应该是-10,000 你知道吗..

上面的代码给你,-10,000如果你设置 $amount = '-10000';

于 2013-10-28T07:20:12.103 回答