Test Whether a String Can Be Converted to a Double in Java
This is a bit of a hack, but I don’t know of any way to do it more elegantly. You kind of wish the Java developers had gone one more step and included this in their framework, but anyway….
The same type of idea should work for Integers, Longs, Floats, etc.
public static boolean IsDouble(String value) { try { Double.parseDouble(value); return true; } catch (Exception ex) { return false; } }
Please let me know if you know of a better way to do this.