Thursday, July 4, 2013

[PHP] 如何讓 數字 格式化 (四捨五入、千分位符號、留小數點幾位...等)

直接看語法:
echo number_format($num,2,'.',',');

範例1:
$num = 1234.129
echo number_format($num,2,'.',',');  //顯示1,234.13

範例2:
$num = 1234.129
echo number_format($num);  //顯示1,234

範例3:
$num = 1234.129
echo number_format($num,4,'.',',');  //顯示1,234.1290

No comments:

Post a Comment