Sie haben viele Möglichkeiten, aber money_format kann den Trick für Sie tun.
// Example:
$amount = '100000';
setlocale(LC_MONETARY, 'en_IN');
$amount = money_format('%!i', $amount);
echo $amount;
// Output:
"1,00,000.00"
Bitte beachten Sie, dass money_format()
nur, wenn das System strfmon
Fähigkeiten definiert ist. Zum Beispiel, Windows nicht, so ist es in Windows undefiniert.
Finale edit: Hier ist eine reine PHP-Implementierung, die auf jedem System funktioniert:
$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.
}
number_format (' '$ Beispiel 2,''); wird das Ding für dich machen .. – Reshil
Da du neu hier bist, akzeptiere die Antwort (tick), die dein Problem gelöst hat. Up-Vote (Pfeil nach oben) die Antwort (en), die Ihnen Informationen geben oder Ihnen helfen. Stimmen Sie (nach unten) die Antwort (en) ab, die gefälscht sind. – Techie
Hinweis: Wenn du das Trennzeichen länger als 1 Zeichen verwenden willst (zB " "), funktioniert das bei php <5.4.0 leider nicht. – UbiQue