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.
The above is the detailed content of How to Format Integers as Currency in MySQL Queries?. For more information, please follow other related articles on the PHP Chinese website!