Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format number with "." as thousand separator, and "," as decimal separator?

Tags:

sql

mysql

how to format number with "." as thousand separator, and "," as decimal separator in MySql?

I'm using Format function like

SELECT Format(myNumber,2) as myNumberFormatted FROM ...

But return type is a number like:

1,000,000.00

instead i want

1.000.000,00

How to do in MySQL ?

Thanks

like image 962
stighy Avatar asked Oct 15 '13 08:10

stighy


People also ask

How do I format a thousand separator?

Select the cells that you want to format. On the Home tab, click the Dialog Box Launcher next to Number. On the Number tab, in the Category list, click Number. To display or hide the thousands separator, select or clear the Use 1000 Separator (,) check box.

How do you change a thousand separator in numbers?

Click File > Options. On the Advanced tab, under Editing options, clear the Use system separators check box. Type new separators in the Decimal separator and Thousands separator boxes.

What is the correct decimal separator?

In the United States, we use the decimal or period (“.”) to represent the difference between whole numbers and partial numbers. We use the comma (“,”) to separate groups of three places on the whole numbers side. This might be different from the way you currently write numbers.

What is an example of decimal separator?

Decimal point and decimal comma are also common names for the decimal separator. For example, 9.5 means nine and one half in English speaking countries, while in many European countries, the same number might be written as 9,5.


2 Answers

MySQL>=5.5:

SELECT FORMAT(10000000.5, 2, 'de_DE') AS format

MySQL<5.5:

SELECT REPLACE(REPLACE(REPLACE(FORMAT(10000000.5,2), ',', ':'), '.', ','), ':', '.') AS format
like image 87
Alma Do Avatar answered Sep 22 '22 01:09

Alma Do


specify locale.

FORMAT(myNumber, 2, 'de_DE')
  • SQLFiddle Demo
like image 31
John Woo Avatar answered Sep 25 '22 01:09

John Woo