How do I calculate the percentage of a number?

John Smeuth picture John Smeuth · Apr 18, 2012 · Viewed 225.1k times · Source

I would like to calculate, in PHP, the percentage of a number. For example:

$percentage = 50;
$totalWidth = 350;

For this example, 50% of 350 = 175

How can I do that?

Answer

pogeybait picture pogeybait · Apr 18, 2012
$percentage = 50;
$totalWidth = 350;

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