Jump to content

GOLF HANDICAP CALCULATOR HELP


wchamber22

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/267048-golf-handicap-calculator-help/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.