MySQL: FORMAT Function
This MySQL tutorial explains how to use the MySQL FORMAT function with syntax and examples.
Description
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.
Syntax
The syntax for the FORMAT function in MySQL is:
FORMAT( number, decimal_places )
Parameters or Arguments
- number
- The number to format.
- decimal_places
- The number of decimal places to round the number.
Note
- If decimal_places is 0, then the FORMAT function returns a string with no decimal places.
Applies To
The FORMAT function can be used in the following versions of MySQL:
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
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); Result: '12,345.68' mysql> SELECT FORMAT(12345.6789, 1); Result: '12,345.7' mysql> SELECT FORMAT(12345.6789, 0); Result: '12,346'
Advertisements