si hanno molte opzioni, ma money_format può fare il trucco per voi.
// Example:
$amount = '100000';
setlocale(LC_MONETARY, 'en_IN');
$amount = money_format('%!i', $amount);
echo $amount;
// Output:
"1,00,000.00"
prega di notare che money_format()
è definito solo se il sistema ha strfmon
capacità. Ad esempio, Windows non lo è, quindi non è definito in Windows.
montaggio finale: Ecco un Attuazione puro PHP che funziona su qualsiasi sistema:
$amount = '10000034000';
$amount = moneyFormatIndia($amount);
echo number_format($amount, 2, '.', '');
function moneyFormatIndia($num){
$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.
}
fonte
2013-07-22 05:47:27
number_format (' '$ esempio, 2,,','); farai la cosa per te .. – Reshil
Dato che sei nuovo qui, accetta la risposta (tick) che ha risolto il tuo problema. Up-vote (freccia su) la/le risposta/e che/i fornisce/i/tu/i/i/i/tu/tu/i/i/i. Down-vote (freccia giù) la risposta (s) che sono falsi. – Techie
Suggerimento: se si desidera utilizzare il separatore più lungo di 1 carattere (es. " ") che non funzionerà in php <5.4.0, sfortunatamente .. – UbiQue