qod*_*nja 1 php decimal number-formatting
价格以美分为单位,但每当价格低于10美元时,价格不会增加.00!
$price = (float)($cents/100);
$price = number_format($price,2);
Run Code Online (Sandbox Code Playgroud)
我想能够代表0.00和0.01和1.01不知道如果number_format()不起作用怎么做!
看看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
?>
Run Code Online (Sandbox Code Playgroud)