This tutorial explains how to use the MySQL FORMAT function with syntax and examples.
The MySQL FORMAT function formats a number as a format of '#,###.##', rounding it to a certain number of decimal places and then it returns the result as a string.
The syntax for the FORMAT function in MySQL is:
FORMAT( number, decimal_places )
The number to format.
The number of decimal places to round the number.
The FORMAT function can be used in the following versions of MySQL:
Let's look at some MySQL FORMAT function examples and explore how to use the FORMAT function in MySQL.
For example:
mysql> SELECT FORMAT(12345.6789, 2);
Output: '12,345.68'
mysql> SELECT FORMAT(12345.6789, 1);
Output: '12,345.7'
mysql> SELECT FORMAT(12345.6789, 0);
Output: '12,346'