2013-10-11 38 views
2

我試圖格式化下列方式PHP number_format()函數

12,34,56,789.00 

我試圖

number_format($row{'money'},2,".",",")

我越來越

123,456,789.00 

這不是我的號碼我想要什麼。那麼,如何做到這一點? (12,34,56,789.00

+4

的'number_format()'方法格式來定義/標準組內的一個數(即數千,數百萬等)。您要求的格式,2個數字+逗號+2個數字+逗號,不是標準格式。你必須編寫自己的函數來做這個分組(可能用'money_format()')。 – newfurniturey

+1

你不能用number_format做到這一點,因爲函數的目的是顯式地「用一組數字格式化一個數字」_。 – CBroe

回答

4

你能夠通過使用PHP函數做這個叫money_format

$amount = '123456789.00'; 
setlocale(LC_MONETARY, 'en_IN'); 
$amount = money_format('%!i', $amount); 
echo $amount; // 12,34,56,789.00 

功能money_format()如果系統的strfmon能力只被定義。例如,Windows不會,所以money_format()在Windows中未定義。

因此可以使用這個PHP代碼:

setlocale(LC_ALL, ''); // Locale will be different on each system. 
$amount = 123456789.00; 
$locale = localeconv(); 
echo number_format($amount, 2, $locale['decimal_point'], $locale['thousands_sep']); 
+0

我正在使用Windows並像你說的那樣不起作用 – LynAs

+1

它工作嗎? ,如果你保持$金額爲123456789(不包括.00) – Sriraman

+0

沒有它的不工作。我用底部代碼btw – LynAs