ID EN
String Functions and Operators

FORMAT(X,D[,locale])

MySQL 8.4 🇮🇩 Bahasa Indonesia

Memformat angka X ke format seperti '#,###,###.##', dibulatkan ke tempat desimal D, dan mengembalikan hasilnya sebagai string. Jika D adalah 0, hasilnya tidak memiliki titik desimal atau bagian pecahan. Jika X atau D adalah NULL, fungsi mengembalikan 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'

Contoh

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'