有可能做到这一点吗? 例如,如果我有
$row['price']
其值为 15000 我希望它显示为 15,000,但我不知道该怎么做? 感谢您的帮助。
最佳答案
那么,您想格式化您的数据吗?使用 FORMAT
函数怎么样?
FORMAT(X,D)
Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part. D should be a constant value.
mysql> SELECT FORMAT(12332.123456, 4);
-> '12,332.1235'
mysql> SELECT FORMAT(12332.1,4);
-> '12,332.1000'
mysql> SELECT FORMAT(12332.2,0);
-> '12,332'
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_format
编辑:示例查询
与人们使用(太频繁)的 SELECT * 相反,稍微修改您的查询。
SELECT id, fullName, position, FORMAT(pay, 0) as pay
FROM Employees WHERE lastName = 'Rubble';
关于mysql - 在 mysql_fetch_array 结果的最后三位数字之前插入逗号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7515479/