php 四舍五入
php round a number
我有一个变量
$amount = 621.00;
我需要输出 186.30 的变量的 30%
当我计算时:
$amount2 = round($amount*30/100 , 2);
echo $amount2
给出 186.3 的输出
如何输出 186.30
您可以使用number_format
例如number_format($amount2, 2)
number_format()
应该可以解决问题。
// english notation without thousands separator
$amount2 = number_format($amount2, 2, '.', '');
// 1234.57
你可以使用 number_format:
$amount2 = number_format($amount * 30 / 100, 2);
echo $amount2;
在最后使用number_format($amount2,2)
。
我有一个变量
$amount = 621.00;
我需要输出 186.30 的变量的 30%
当我计算时:
$amount2 = round($amount*30/100 , 2);
echo $amount2
给出 186.3 的输出
如何输出 186.30
您可以使用number_format
例如number_format($amount2, 2)
number_format()
应该可以解决问题。
// english notation without thousands separator
$amount2 = number_format($amount2, 2, '.', '');
// 1234.57
你可以使用 number_format:
$amount2 = number_format($amount * 30 / 100, 2);
echo $amount2;
在最后使用number_format($amount2,2)
。