dzhax Posted January 23, 2014 Share Posted January 23, 2014 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. Link to comment Share on other sites More sharing options...
Ingolme Posted January 23, 2014 Share Posted January 23, 2014 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. Link to comment Share on other sites More sharing options...
dzhax Posted January 23, 2014 Author Share Posted January 23, 2014 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. Link to comment Share on other sites More sharing options...
Ingolme Posted January 23, 2014 Share Posted January 23, 2014 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now