开发者

convert number to decimal in php

I have a number stored in a variable. The numb开发者_StackOverflow社区er 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.


$priceInCents = 9900;
$priceInDollars = $priceInCents / 100;

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


You can use the number_format() function for that:

echo number_format(9900/100);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜