ID EN
String Functions and Operators

FORMAT(X,D[,locale])

MySQL 8.4

Formats the number X to a format like '#,###,###.##', rounded to D decimal places, and returns the result as a string. If D is 0, the result has no decimal point or fractional part. If X or D is NULL, the function returns NULL.

Syntax

MYSQL
SELECT FORMAT(12332.123456, 4);
'12,332.1235'
SELECT FORMAT(12332.1,4);
'12,332.1000'
SELECT FORMAT(12332.2,0);
'12,332'
SELECT FORMAT(12332.2,2,'de_DE');
'12.332,20'

Examples

Example

The optional third parameter enables a locale to be specified to be used for the result number's decimal point, thousands separator, and grouping between separators. Permissible locale values are the same as the legal values for the lc_time_names system variable (see Section 12.16, “MySQL Server Locale Support”). If the locale is NULL or not specified, the default locale is 'en_US'.

MYSQL
SELECT FORMAT(12332.123456, 4);
'12,332.1235'
SELECT FORMAT(12332.1,4);
'12,332.1000'
SELECT FORMAT(12332.2,0);
'12,332'
SELECT FORMAT(12332.2,2,'de_DE');
'12.332,20'