PHP
FORMAT NUMBER AS CURRENCY IN PHP
THE NUMBER $amount = 6543.21;
FORMAT NUMBER
01
US DOLLARS - $6,543.21 $usd = "$"; $usd .= number_format($amount, 2, ".", ",");
JAPANESE YEN - ¥6,543 $jpy = "¥"; $jpy .= number_format($amount, 0, ".", ",");
THE NUMBER $amount = 6543.21;
REGULAR EXPRESSION
02
REGULAR EXPRESSION - $6,543.21 $regex = "/\B(?=(\d{3})+(?!\d))/i"; $usd = "$" . preg_replace($regex, ",", $amount);
THE NUMBER $amount = 6543.21;
NUMBER FORMATTER
03
US DOLLARS - $6,543.21 $nf = new NumberFormatter("en_US", NumberFormatter::CURRENCY); $usd = $nf->formatCurrency($amount, "USD");
JAPANESE YEN - ¥6,543 $nf = new NumberFormatter("ja_JP", NumberFormatter::CURRENCY); $jpy = $nf->formatCurrency($amount, "JPY");