有没有办法在PHP中将0格式化为空格?我知道如何改变正负值的格式而不是0,使用类似的东西:
$final = number_format($number,2);
答案 0 :(得分:1)
$final = $number ? number_format($number,2) : "";
答案 1 :(得分:0)
这应该适合你:
<?php
$number = 3.12;
if (substr(number_format($number,2), -2) == 0)
$final = $number;
else
$final = number_format($number,2);
echo $final;
?>
输入/输出:
//number = 3.00
//Output = 3
//number = 3.12
//output = 3.12