The FORMAT() function formats a number with commas and rounds to a given number of decimal places, returning the result as a string.
MySQL FORMAT Function Syntax
SQL
x
1
FORMAT(number, decimal_places)
MySQL FORMAT Function Example
This query formats the number 250500.5634 to two decimal places with commas.
SQL
1
1
SELECT FORMAT(250500.5634, 2) AS FormattedNumber;
Note: This example does not work in SQLite or the TechKubo Playground. FORMAT() is only supported in MySQL.
MySQL FORMAT Function Parameters
Parameter | Description |
---|---|
number | Required. The number to be formatted |
decimal_places | Required. Number of decimal places for the result |
MySQL FORMAT Function Table Column Example
This query would format a numeric column with two decimals.
SQL
1
1
SELECT FORMAT(record_id, 2) AS FormattedRecordID
2
FROM MedicalRecords;
Note: This example does not work in SQLite or the TechKubo Playground. FORMAT() is not supported.
MySQL FORMAT Function Notes
- Returns the formatted number as a string.
- Only supported in MySQL (not in SQLite or the TechKubo Playground).
- Using it in SQLite/TechKubo will result in an error.