php percentage – how to get percentage of value in php ?

php percentage calculating a percentage is just basic math Calculate the percentage of a number. Use the following Examples to find the percentage value of one number to another.

php percentage

PHP: Calculate the percentage of a number.

PHP calculate percentage of total

PHP program to calculate percentage

';
echo "Results of 26 in 200 : ".getCalcPer(26, 200).'%
'; echo "Results of 17 in 150 : ".getCalcPer(17, 150).'%
'; echo "Results of 30 in 400 : ".getCalcPer(30, 400).'%
'; echo "Results of 11 in 190 : ".getCalcPer(11, 190).'%
'; ?>

Output of the above code –

Results of 39 in 100 : 39%
Results of 26 in 200 : 13%
Results of 17 in 150 : 11%
Results of 30 in 400 : 8%
Results of 11 in 190 : 6%

Example


don't Miss : calculate percentage in php

Get Percentage Of A Number With PHP

function getCalcPer($total, $number)
{
  if ( $total > 0 ) {
   return round(($number * 100) / $total, 2);
  } else {
    return 0;
  }
}

sample examples of the function in action.

echo getCalcPer(100,50).'%'; // 50%
echo getCalcPer(100,10).'%'; // 10%
echo getCalcPer(100,100).'%'; // 100%
echo getCalcPer(400,3).'%'; // 0.75%
echo getCalcPer(1234,4321).'%'; // 350.16%

I hope you get an idea about php percentage.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment