开发者

How do you get number_format() to add two decimal points on integers less than 10?

The price is in cents, but whenever th开发者_C百科e price is less than $10 its not adding .00!

              $price = (float)($cents/100);
              $price = number_format($price,2);   

I want to be able to represent 0.00 and 0.01 and 1.01 not sure how to do this if number_format() doesnt work!


Take a look at money_format.

<?php

$prices = array(100, 10, 1, 0.10, 0.01);
foreach ($prices as $price) {
    echo money_format('%.2n', $price) . "\n";
}

// 100.00
// 10.00
// 1.00
// 0.10
// 0.01
?>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜