我將如何迴應的數值爲逗號分隔逗號分隔的數值 - PHP笨
foreach($report_value as $value):
echo round($value['report_total_cost_usd'],2); // ex: 1,234,456.00
endforeach;
我將如何迴應的數值爲逗號分隔逗號分隔的數值 - PHP笨
foreach($report_value as $value):
echo round($value['report_total_cost_usd'],2); // ex: 1,234,456.00
endforeach;
MySQL的解決方案:
使用format
上與小數的輸入數量的功能。
例:
mysql> select format(1234456, 2);
+----------------------+
| format(1234456, 2) |
+----------------------+
| 1,234,456.00 |
+----------------------+
你可以從你的腳本語言和使用讀一樣的字符串。
參考:
'#,###,###.##'
格式,四捨五入到D
小數位,並返回結果爲string
。如果D
爲0
,則 結果沒有小數點或小數部分。@zzlalani:看來,你在錯誤的地方發表了評論! –
這是你在找什麼number_format
echo number_format($value['report_total_cost_usd'], 2, '.', ','); // ex: 1,234,456.00
輸出
1,234,456.00
需要對工作的一些奉獻,有的知識如何閱讀說明書..
試試這個
foreach($report_value as $value)
{
echo number_format($value['report_total_cost_usd'],2,'.', ','); // ex: 1,234,456.00
}
輸出是'1,234,456'而不是'1,234,456.00' – zzlalani
爲什麼我的代碼不粘貼? – Kentot
U需要在每行的起始位置放置4個空格或突出顯示代碼並按代碼塊按鈕 –
使用'number_format'功能例如 –