This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Is there a Java class that provides a method to convert a string to the appropriate numeric data type (int, float, double) based on the contents of the string. (Whether the String contains a decimal point and the number of digits.)
I can write this logic from scratch, but want to use the "standard" way to do this, if there is one.
If you're using JDK 5+ I would recommend Scanner, using methods like hasNextInt() and nextInt(). The nice thing about Scanner is that if the input can't be pared as an int (or whatever numeric type you want) you can detect this easily beforehand using hasNextInt(). Prior to JDK 5 the standard option was to use Integer.parseInt(), but in that case you need to catch an exception in case of bad input.
And yes, I agree that NumberFormat / DecimalFormat are probably best if you need to customize the format options. In my experience that's been pretty rare, but it could happen.