Most of the time we are used to format float numbers into currency format by PHP (or any front end language) using functions like fprintf(). If we could grab the result formatted from the db, we won’t need to use front end formatting. Mysql function format() is the function we need.
Lets say we have a table with float field price and we want to show the price in formatted string. The sql query would be something like this:
select concat('£', format(price, 2)) as price from TABLE_NAME;
The result set will have the formatted output ready to be displayed on the browser. You can see the mysql function detail here.


#1 by Will on November 10th, 2009
… except, of course, that nobody would ever store monetary values as a float, because that would be wrong.
#2 by imran on November 12th, 2009
you are kind of correct. Thanks