Jump to content

PHP Min Max


sunziun
 Share

Recommended Posts

Hello Everyone, right now I am trying to do an small app that can calculate fees based on the price a user has given. Example: $0.01 - $0.99 = $0.09$1 - $5.99 = $0.13$99 or more = $1.34 So far I have this code but I cannot get it to work properly:

	 if($start < 1.00){	    echo "<p>" . $ins_fees[0] . $sym . $ins_fees[1] . "</p>";		 // FURTHER CALCULATION    }		 if($start == 1.00){	    echo "<p>" . $ins_fees[0] . $sym . $ins_fees[2] . "</p>";		 // FURTHER CALCULATION    } else{	    if($start > 1){		    echo "<p>" . $ins_fees[0] . $sym . $ins_fees[2] . "</p>";		 // FURTHER CALCULATION	    }    } 

thanks for everyone!

Link to comment
Share on other sites

What error messages are you getting? Many errors are possible.

Edited by niche
Link to comment
Share on other sites

You have a condition for each price range From 0 to 0.99: (price < 1) fee = 0.09From 1.00 to 5.99: (price >= 1 && price < 6) fee = 0.1399 or above: (price >= 99) fee = 1.34

Link to comment
Share on other sites

Guest So Called
$0.01 - $0.99 = $0.09$1 - $5.99 = $0.13$99 or more = $1.34
if ($amount >= 0.01 && $amount <= 0.99) $fee = 0.09;elseif ($amount <= 5.99) $fee = 0.13;elseif ($amount >= 99) $fee = $1.34;

Note that you have some gaps that you will want to fill in. Note also that it is not necessary to test in the second line for > .99 because the first line will have caught that and the second line will not execute. (Beware the $0.00 problem.) If I were writing the code I would structure it a bit differently:

if ($amount < 0.01) $fee = 0;elseif ($amount < 1.00) $fee = 0.09;elseif ($amount < 6.00) $fee = 0.13;elseif ($amount < 99.00) $fee = ....;else $fee = $1.34;

I'm sure you get the idea.

Edited by So Called
Link to comment
Share on other sites

Hello, unfortunately none is working. I have a form which the user enters his amount. Based on that the result.php page should calculate and display the fees applicable. I was playing with range() but I cant find out how to implement the $amount variable.

if(range($amount, 0.99, $step) ) echo $fee=0.00;elseif(range($amount,4.99,$step)) echo $fee=0.09;

it displays only a 0 (zero) even when i put in amount of 4.50

Link to comment
Share on other sites

Guest So Called

In my example I used $amount. Evidently you used $start. It's the amount of the transaction, no matter what you call it. It's the value you are looking up to get the fee.

Link to comment
Share on other sites

I got it now and this works like a charm

	    if($start > 0.00 && $start < 1.00) $fee=0.09;	    elseif($start > 0.99 && $start < 5.00) $fee=0.13;	    else echo $fee=1.34;

@ So Called the zero problem will be controlled by a minimum form validation of 0.01.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...