I see your code makes comparisons with doubles - which is quite hazardous. Floating point numbers can't represent all values - they have to (very closely) approximate some of them.
The "cleanest" way to work with numbers that must be compared, is to use a multiplier, and then cast them to integers. So 100.68 would become 10068, for example. Do that RIGHT AWAY, with every float value. Then, for your output, cast it back to a double, and divide it by the same power of ten that you multiplied it by.
Another way, is to make your comparisons within a small range, instead of a fixed value. if double > 4.89 && double < 4.91 kind of logic.
If you google for "problem comparing floats", you'll find a lot more info on it.