try{
 float f = Float.parseFloat(str);
}catch(Exception e){}

解决方案 »

  1.   

    "5.14" -> 5.14helpall说的对
      

  2.   

    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)
      

  3.   

    String s;
    ...
    try
    {
     float f = Float.parseFloat(s);
    }
    catch(NumberFormatException e)
    {
    //...
    }