Jump to content
Sign in to follow this  
dzhax

Finding the min value

Recommended Posts

So I have a slider on my page. I need to determine the minimum amount via php.

 

I know this is more a math question than a php question.

 

I have a variable called $perCost. This variable is the cost of 1 unit.

 

I need to determine how many units must be purchased for the total cost to equal at least $minPurchase.

 

This value i will then set as the minimum value of the slider.

 

Any help on this would be much appreciated.

Share this post


Link to post
Share on other sites

You haven't explained the problem well enough for me to understand. Is $minPurchase set beforehand or do we have to figure it out?

 

If you want to know how many $perCost for a $minPurchase, just do a division: $minPurchase/$perCost.

Share this post


Link to post
Share on other sites

yes for the sake of an example

$perCost = 0.016

$minPurchase = 0.2

Although both of these variable may change.

 

I need to determine how many full units must be purchased in order to meet the minPurchase limit.

Share this post


Link to post
Share on other sites

This is elementary school math, a linear one-variable equation.

 

0.016 × x = 0.2 therefore x = 0.2÷0.016

 

Substitute it with the input variables

 

perCost × x = minPurchase therefore x = minPurchase ÷ perCost

 

The minimum amount needed to reach the price is ceil($minPurchase/$perCost). I use ceil() because if the result of the division is 1.2 you actually want 2 rather than 1.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...