如何计算数字的百分比


How do I calculate the percentage of a number?

我想用PHP计算一个数字的百分比。例如:

$percentage = 50;
$totalWidth = 350;

在本例中,350 的 50% = 175

我该怎么做?

$percentage = 50;
$totalWidth = 350;
$new_width = ($percentage / 100) * $totalWidth;

$percentage除以 100 并乘以 $totalWidth .简单的数学。