How to display two decimal places in MYSQL / PHP?

I would like to display £ 2.00 instead of £ 2 or £ 3.50 instead of £ 3.5 .

These numbers say it priceis defined as DOUBLEin a MySQL database. How to get MySQL or PHP to display two decimal places?

Many thanks!

+3
source share
4 answers

Try the following:

echo number_format ($price, 2);
+6
source

For MySQL you can use the function format:

SELECT FORMAT(1.2345, 2);

He will return 1.23

For PHP you can use in a number_formatsimilar way:

echo number_format(1.2345, 2);

Also stamp 1.23

+9
source

, .

, , DOUBLE - , .

, DOUBLE ; , . , , , . MySQL , DECIMAL, (.. ) .

+4

All Articles