Reputation: 5747
At the moment I store prices for products in the database as a pence number. So 4321 in the database means £43.21.
Then when reading it out, I divide by 100 to get it in pound and pence format.
However, I have a problem.
If the price is 4320, the returned value is 43.2 without the 0.
How can I get around this?
Thanks!
Upvotes: 0
Views: 912
Reputation: 20602
money_format()
should do the trick. Alternatively number_format()
or the powerful printf()
.
Upvotes: 1
Reputation: 43239
<?
echo money_format("%i", 1234.5)
//Output: 1234.50
?>
You can use money_format.
Upvotes: 2
Reputation: 96266
echo number_format($float, 2, '.', '');
and for pretty printing of large values:
echo number_format($float, 2, '.', ',');
Upvotes: 0