views:

48

answers:

3

Hi guys,

I have a number stored in a variable. The number is pulled from the database as 9900..I need to convert this number to 99.00 in order to display to a customer in HTML.

I was wondering how can I achieve this in php.

Thanks.

+2  A: 

You can use the number_format() function for that:

echo number_format(9900/100);
Kau-Boy
+2  A: 
$priceInCents = 9900;
$priceInDollars = $priceInCents / 100;

And then you can use round() or number_format() as you please.

jensgram
+1  A: 

You can do this by either using money_format or number_format, if you are going to display it as a price you should look at money_format, otherwise, number_format is the way to go.

Kristoffer S Hansen
I didn't knew about the money function. Very handy, even tough the euro format is not correct.
Kau-Boy