PHP中显示浮点数时,保留两位小数的代码应该如何写呢?
我们可以使用number_format()函数:
return number_format((float)$number, 2, '.', '');
案例代码:
$foo = "105";
echo number_format((float)$foo, 2, '.', ''); // Outputs -> 105.00
需要注意的是:这个函数将会返回一个字符串。
PHP中显示浮点数时,保留两位小数的代码应该如何写呢?
我们可以使用number_format()函数:
return number_format((float)$number, 2, '.', '');
案例代码:
$foo = "105";
echo number_format((float)$foo, 2, '.', ''); // Outputs -> 105.00
需要注意的是:这个函数将会返回一个字符串。