我想在PHP中计算一个数字的百分比。例如:
$percentage = 50;
$totalWidth = 350;
举例来说,350的50%等于175。
我该如何做到这一点?
我想在PHP中计算一个数字的百分比。例如:
$percentage = 50;
$totalWidth = 350;
举例来说,350的50%等于175。
我该如何做到这一点?
$percentage = 50;
$totalWidth = 350;
$new_width = ($percentage / 100) * $totalWidth;
$percentage
除以100,然后乘以$totalWidth
。简单的数学运算。
($totalWidth*$percentage)/100
。虽然结果一样,但是我更喜欢这种方式。 - vinsa$new_width = $percentage / 100 * $totalWidth;
是相同的。 - Eugen Zaharia