How to tell if a number is a double?
843789Apr 12 2010 — edited Apr 13 2010I'm hesitant to ask the question, because after a Google search I found a few other forums where the poor bloke asking this was crucified for being an idiot. Hopefully we're a little less egotistical here.
... and in the end there was still no really elegant solution given.
The only solution I thought of was to use Integer.parseInt(String) and catch the exception if it's not an Integer. But is converting a number into a String and then purposefully writing code that throws exceptions considered elegant programming??? I wouldn't have guessed so.
The reason I need to do this is to find the median of a set of numbers. My though process (maybe naive) is: 1. get the count of number in the set; 2. halve the count; 3. if the half is a double then the central number was "split" down the middle so that number is the median; however if the number is not a double, then the average of the two numbers to either side of the "split" is the median.
But I need to be able to tell if the number is a whole number or not.
... and excuse me if I've missed something obvious. I am afterall only a humble novice, dwarfed in intellect and programming ability by the average Internet forum member (apparently). ;-)