FORMAT Function
In this page:
Basic Number Formatting
FORMAT rounds a number to a chosen number of decimal places and inserts comma separators for readability, turning something like 1234567.891 into '1,234,567.89' for display purposes.
Example: Basic Number Formatting
SELECT FORMAT(1234567.891, 2) AS formatted;
Locale-Specific Formatting
An optional third argument lets you specify a locale, changing which characters are used as the thousands separator and decimal point to match regional conventions — some locales use a period where others use a comma, and vice versa.
Example: Locale-Specific Formatting
SELECT FORMAT(1234567.891, 2, 'de_DE') AS german_format;
Formatting Large Numbers
Formatted output makes a real difference in reports and dashboards, since large statistics or totals are much easier to scan at a glance once they're broken into readable groups of three digits.
Example: Formatting Large Numbers
CREATE TABLE stats (id INT, total_users INT);
INSERT INTO stats VALUES (1, 1234567);
SELECT FORMAT(total_users, 0) AS readable_total FROM stats;
Formatting with Zero Decimals
Setting the decimal-place argument to 0 gives you comma-grouped output with no fractional part at all, which is handy for whole-number counts like total orders or user sign-ups where decimals would be meaningless.
Example: Formatting with Zero Decimals
SELECT FORMAT(48210, 0) AS signups;
FORMAT vs ROUND
FORMAT always returns a text string, while ROUND returns a plain number you can still do math with. Use FORMAT only at the point where you're displaying a value to a user, and keep calculations running on the unformatted number.
Example: FORMAT vs ROUND
SELECT FORMAT(1234.5678, 2) AS display_value, ROUND(1234.5678, 2) AS math_value;
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: