The Codesee The Codesee - 5 months ago 11
PHP Question

Check if number is less than another number by a certain percentage

I would like to check if

$Price1
is less than
$Price2
by 40% or more.

$name = 'bob';
$price1 = '100';
$price2 = '300';

if($price1 < $price2) {
echo $name;
}


The above code doesn't check if
$price1
is less than by a percentage.

Answer
$name = 'bob';
$price1 = '100';
$price2 = '300';

if($price1 < 0.6*$price2) {
   echo $name;
}
Comments