try{ String str; float f = Float.parseFloat(str); }catch(NumberFormatException e){}jdk下是 parseFloat public static float parseFloat(String s) throws NumberFormatException Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float. Parameters: s - the string to be parsed. Returns: the float value represented by the string argument. Throws: NumberFormatException - if the string does not contain a parsable float. Since: 1.2 See Also: valueOf(String)
String str;
float f = Float.parseFloat(str);
}catch(NumberFormatException e){}jdk下是
parseFloat
public static float parseFloat(String s)
throws NumberFormatException
Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Float. Parameters:
s - the string to be parsed.
Returns:
the float value represented by the string argument.
Throws:
NumberFormatException - if the string does not contain a parsable float.
Since:
1.2
See Also:
valueOf(String)
...
try
{
float f = Float.parseFloat(s);
}
catch(NumberFormatException e)
{
//...
}