How do I calculate the percentage of a number?

PhpPercentage

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

$percentage = 50;
$totalWidth = 350;

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

Solution 2 - Php

Divide $percentage by 100 and multiply to $totalWidth. Simple maths.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn SmeuthView Question on Stackoverflow
Solution 1 - PhppogeybaitView Answer on Stackoverflow
Solution 2 - PhphkfView Answer on Stackoverflow