Calculate the difference in percentage

Views: 8 Last modified: August 03rd, 2011 Comments: 0

This function will calculate the difference in % between X and Y. X must be less then Y.

function CalcDiffPer($n1, $n2)
{
   if ($n2 < $n1) list($n1, $n2) = array($n2, $n1);
   return sprintf('%.1f', (100 - ( ($n1 / $n2) * 100))).'%';
}

echo CalcDiffPer(75,100);
VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

    Mail this!

    To: From:Sum {0+1} =  
    Anything to add ?

        You must be logged in to post a comment.