如何在php中为美元的美分金额添加额外的0


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

$dollar_amount_purchased = $dollar_amount_purchased + "0";

我尝试了上面的代码,但它不工作。在php中怎么做呢?

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

您应该看看http://php.net/manual/en/function.number-format.php

number_format格式显示数字。第一个参数是要显示多少位小数。如果你指定2,而数字没有十分位或百分位,它将自动被0填充。

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