Okie....
I have $variable1, $variable2 and $variable3.
My question is how to get $variable3 to show the percentage of the result of $variable2 - $variable1.
The values for $variable1 and $variable2 are going to be submitted via a form by the user and the result of the subtraction should be a % that will be assigned to $variable3. The percentage can be positive or negative.
For example:
$variable1 = 11.54
$variable2 = 10.45
$variable3 = -9.45%
Any help is appreciated.
FayeC
Calculating a percentage with the result of a subtraction
Moderator: General Moderators
Re: Calculating a percentage with the result of a subtraction
Code: Select all
$v1 = 11.54;
$v2 = 10.45;
$v3 = (($v1 - $v2)/$v1) * 100;
echo $v3;