Home » Php » php – Adding Percentage of Number to Itself

php – Adding Percentage of Number to Itself

Posted by: admin July 12, 2020 Leave a comment

Questions:

I want to add 30.4 percent of $drivervalue to $drivervalue, is it possible to do that as below? I know if I knew what the actual number was going to be I could just put the 30.4 after the 1., but as I wont know what it will be, I am using the variable instead is this a valid syntax?

//example

$drivervalue = 16000000;

$percentdiff = 30.4;

$drivvalue *= 1. $percentdiff;
How to&Answers:
$drivervalue *= (1 + $percentdiff / 100);

Answer:

 $num = 100;
 $percentage = 30.4;
 $num += $num*($percentage/100); // results in 130.4

Answer:

$drivervalue = $drivervalue * (1 + ($percentdiff / 100));