开发者

convert number to decimal in php

开发者 https://www.devze.com 2023-01-16 02:49 出处:网络
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 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

精彩评论

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