0

Okay I am trying to work out a math equation in PHP with no avail. Here's what I am trying to accomplish.

$staticprice = '345.00'; //always the same
$uservalue = $_POST['value'];
if($uservalue is 30% or less than $staticprice){ die();}

So I don't want user's value to be 30% or less than the static price.

How would I go by accomplishing this?

spondee
  • 23
  • 1
  • 6
john smith
  • 327
  • 2
  • 16

3 Answers3

2
if($uservalue <= ($staticprice * 0.3))
   die();

Something like this?

Drown
  • 5,852
  • 1
  • 30
  • 49
1
$staticprice = 345.00; //always the same
$uservalue = $_POST['value'];
if($uservalue <= ($staticprice * 0.3)){ die();}
TRGWII
  • 648
  • 5
  • 14
0

This is simple math:

$staticprice = '345.00'; //always the same
$uservalue = $_POST['value'];
if($uservalue / $staticprice * 100 == 30 || $uservalue  < $staticprice){ die();}

But you don't even have to check if it is equal to 30 percentage. Because if you also want the if statement to be true if $uservalue is less then $staticprice you only have to write this:

$staticprice = '345.00'; //always the same
$uservalue = $_POST['value'];
if($uservalue  < $staticprice){ die();}
Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • == 30? that will be true in 1% of all cases. – designosis Feb 06 '15 at 19:28
  • @neokio OP wrote that i pseudo code: `$uservalue is 30%`, But since he also wrote: `or less than $staticprice` He only has to check if the uservalue is less then the staticprice – Rizier123 Feb 06 '15 at 19:29