我正在尝试将数字转换为印度货币格式LIke
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
你有什么想法..
答案 0 :(得分: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';