Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

number_format() with MySQL

Tags:

hey i need a way to get a formated number from my column decimal(23,2) NOT NULL DEFAULT '0.00'

in php i could use this function number_format('1111.00', 2, ',', '.'); it would return 1.111,00 (in Germany we use , to define decimal numbers)

how would i do this in mysql? with string replaces?

like image 826
antpaw Avatar asked Dec 21 '09 10:12

antpaw


People also ask

How do I get 2 decimal places in MySQL?

SELECT ROUND(-4.535,2); Explanation: The above MySQL statement will round the given number -4.535 up to 2 decimal places.

What is use format in MySQL?

MySQL FORMAT() Function The FORMAT() function formats a number to a format like "#,###,###. ##", rounded to a specified number of decimal places, then it returns the result as a string.

How do I add a thousand separator in MySQL?

MySQL FORMAT function examples As you see in the result, the de_DE locale use dot (.) for grouping thousand and comma (,) for decimal mark.

How do you round off in MySQL?

ROUND() Function in MySQL. The ROUND() function in MySQL is used to round a number to a specified number of decimal places. If no specified number of decimal places is provided for round off, it rounds off the number to the nearest integer.


1 Answers

http://blogs.mysql.com/peterg/2009/04/

In Mysql 6.1 you will be able to do FORMAT(X,D [,locale_name] )

As in

 SELECT format(1234567,2,’de_DE’); 

For now this ability does not exist, though you MAY be able to set your locale in your database my.ini check it out.

like image 178
MindStalker Avatar answered Oct 06 '22 01:10

MindStalker