berridgeab Posted March 18, 2008 Share Posted March 18, 2008 Hi I have not really used the Math calculations in PHP however I have a really probably stupid question. I have Two Variables: - $Price = 20.40 $Discount = 45 How I work out the figure I need on a calculator is: - Key in 20.40 Press Minus Type in 45 and hit the % Sign Works it out to: - 11.22 How would I do this in PHP, I know im doing something really stupid here but if I try and put the % sign in with any other calculation (i.e the minus sign) it causes PHP to error i.e. $FinalCost = $Price - $Discount %; Maybe I just need a brushup on my math. Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted March 18, 2008 Share Posted March 18, 2008 You have two variables which store a value in each,now what do you want to do with these values? Do you want to divide,add,subtract or multiply or calculate the mode value,please specify clearly. Mode:A%B=remainder or 0 if exactly divisible Sub:A-B Mul:A*B Div:A/B and so on. Quote Link to comment Share on other sites More sharing options...
berridgeab Posted March 18, 2008 Author Share Posted March 18, 2008 Hi Thank you for your reply, Basically what I want to do is Find 45% (Percent) of £20.40 which is £11.22. I have finally figured it out however here is the forumla I use: - Deduct Figure = Cost Price * Discount / 100 Final Figure = Cost Price - Deduct Figure Or As in the example above: - 9.18 = 20.40 * 45 / 100 11.22 = 20.40 - 9.18 Thanks for your assistance anyway. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted March 18, 2008 Share Posted March 18, 2008 $FinalCost = $Price - ($Price * ($Discount / 100)); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.