Converting Integers to Currency Format in MySQL Queries
In MySQL, you can transform integer values into currency format while performing selections. While you can append the currency symbol using the CONCAT() function, inserting the comma separators for large numbers requires a more elaborate approach.
Using the FORMAT() Function
The FORMAT() function provides a comprehensive solution for formatting numbers, including conversion to currency format.
Syntax:
FORMAT(val, decimals)
Where:
Example:
To convert the integer 1000 into the currency format "$1,000":
SELECT CONCAT('$', FORMAT(1000, 2)) AS formatted_value;
This query returns the value "$1,000". The FORMAT() function adds the commas as necessary, ensuring a professional currency display.
以上是如何在 MySQL 查詢中將整數格式化為貨幣?的詳細內容。更多資訊請關注PHP中文網其他相關文章!