wchamber22 Posted August 14, 2012 Share Posted August 14, 2012 Once again HELLO FREAKS, I have an equation calculating a users differential for an entered round below: $differential = ($totalScore - $courseRating) * 113 / $courseSlope For example, if I shot (wishful thinking) a 74 at a course with a rating of 70.3 and a course slope of 122. The equation would be (74 - 70.3) * 113 / 122 = 3.42704918. I want that to be 3.4 WITHOUT ROUNDING and believe I have done that with the following code: $differential = explode(".", $differential); $decimal = substr($differential[1],0,1); $differential = $differential[0].'.'.$decimal; My question is: How could I use and if else statement to ONLY run the above code if the number is a decimal on the off chance that the equation works out to be a whole number? FYI, my mysql column differential is a decimal (3,2) Thanks as always! Quote Link to comment https://forums.phpfreaks.com/topic/267048-golf-handicap-calculator-help/ Share on other sites More sharing options...
Mahngiel Posted August 14, 2012 Share Posted August 14, 2012 you should be using round. it will make your like a shit ton easier. $differential = round( ($totalScore - $courseRating) * 113 / $courseSlope, 1) Quote Link to comment https://forums.phpfreaks.com/topic/267048-golf-handicap-calculator-help/#findComment-1369224 Share on other sites More sharing options...
wchamber22 Posted August 14, 2012 Author Share Posted August 14, 2012 Yo Mahngiel, Thanks for the help but I would like to drop all other decimal places WITHOUT rounding. For example, I want 3.4673930 to be 3.4 NOT 3.5 as the round() would do. So do you know how to only execute that code if i have a decimal, if not just skip it because I am assuming it would cause errors if the equation returned a whole number. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/267048-golf-handicap-calculator-help/#findComment-1369235 Share on other sites More sharing options...
darkfreaks Posted August 14, 2012 Share Posted August 14, 2012 have you tried using number_format Quote Link to comment https://forums.phpfreaks.com/topic/267048-golf-handicap-calculator-help/#findComment-1369238 Share on other sites More sharing options...
Barand Posted August 14, 2012 Share Posted August 14, 2012 $h = 3.47; $h = (floor($h * 10)) / 10; Quote Link to comment https://forums.phpfreaks.com/topic/267048-golf-handicap-calculator-help/#findComment-1369243 Share on other sites More sharing options...
xyph Posted August 14, 2012 Share Posted August 14, 2012 Please, don't put your title in all-caps. You risk having it closed. Quote Link to comment https://forums.phpfreaks.com/topic/267048-golf-handicap-calculator-help/#findComment-1369304 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.