开发者

How do I add an extra 0 for the cent amount in dollars in php? [closed]

开发者 https://www.devze.com 2023-03-28 04:08 出处:网络
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

Closed 8 years ago.

Improve this question
$dollar_amount_purchased = $dollar_amount_purchased + "0";

I tr开发者_Python百科ied the above code but it's not working. How am I supposed to do this in php?


http://php.net/manual/en/function.money-format.php


You should have a look at http://php.net/manual/en/function.number-format.php


Format numbers for display with number_format. The first parameter is how many decimal places you want to show. If you specify 2 and the number does not have a tenths or hundredths place, it'll get padded with 0s automatically.

echo '$' . number_format($dollar_amount_purchased, 2, '.', ',');
0

精彩评论

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