php get percentage of two numbers – 3 Ways to calculate a percentage change (increase and decrease) from 2 values in PHP

php get percentage of two numbers: Given 2 numbers old and new, where ‘new’ is incremented or decremented by some percentage of ‘old’. The task is to find out that percentage.

php get percentage of two numbers

Calculate percentage saved between two numbers using PHP: Calculate the percent difference between two numbers.

Let’s say you have two numbers, 50 and 25.

  
  25/50*100 = 75.
  So 25 is 75% of 50.  

  50/25*100 = 133. 
  So 50 is 133% of 25. 

The percentage increase from 25 to 50 is:  
  (50-25)/25 * 100 = 33%  

The percentage decrease from 50 to 25 is:
  (50-25)/50 * 100 = 25%. 

These calculations hold true whatever your two numbers.

Read Also:  How to notify when new record inserted in sql database in php?

Don’t Miss: Calculate Percentage In Php

How to calculate percentage in PHP?

here you call the function to calculate percentage

function getCalculatePercentageChange($percentage, $of) 
{ 
    $percent = $percentage / $of; 
    return  number_format( $percent * 100, 2 ) . '%'; 
} 
 
getCalculatePercentageChange(10, 100);

PHP: Calculate the percent difference between two numbers.

<?php

$first_vlaue = 24;
$second_value = 8.25;

$percentChange = (1 - $first_vlaue / $second_value) * 100;

echo $percentChange;

php get percentage of two numbers

calculate a percentage change (increase and decrease) from 2 values in PHP

function getCalculatePercentageChange($first_vlaue, $second_value){
    $decreaseValue = $first_vlaue - $second_value;

    return ($decreaseValue / $first_vlaue) * 100;
}

PHP: Calculate the percentage difference between two numbers

function percent_diff($old, $new, $final_per = null) {
	$total_calculate = abs((1 - ($old / $new)) * 100);

	if (is_numeric($final_per)) {
		$results = $total_calculate < $final_per;

		return $results;
	}

	return $total_calculate;
}

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