Example: "

**2.5 : 1.5**" should be "

**5 : 3**"

Basically, I wrote a function to convert monitor resolutions into ratios (like 640 x 480 = 4:3)), and it works, but sometimes it reduces the ratios to fractional components. I want them to always be whole numbers. (For example: 1280 x 768)

Here's my ratio function: (The comments in it, especially the math-terminology comments, are for my own benefit)

std::string RatioAsString(float ratio) { float percentage = (100 * ratio); //For example, 100 * 0.75 = 75 percent. float leftOver = 100 - percentage; //For example, 75% out of 100% = 25%. //antecedent = mathematical name for left-hand 'term'. (Term 'A' in A:<img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> //consequent = mathematical name for the right-hand 'term'. (Term 'B' in A:<img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/cool.gif' class='bbc_emoticon' alt='B)' /> float antecedent = 100 / leftOver; //For example, 100% / 25% = 4 float consequent = percentage / leftOver; //For example, 75% / 25% = 3 //Result: antecedent : consequent = 4:3 return FloatToString(antecedent) + ":" + FloatToString(consequent); }(I'm aware that this function doesn't do well with ratios greater than 1.0, I just realized that and came up with a fix - but that's not my problem)

How would I even check in C++ if a float is a whole number or not? A quick google suggests that if "floor(n) == n" then it's a whole number, but surely floating point precision may give false positives (is 3.0 equal to 3.0000000001)?

Once I

*do*know that is non-whole, then what do I do?