string s = "123.456";
double result = 0;try {
    result = Double.parseDouble(s);  // usage of parseDouble()
    result = Double.valueOf(s).doubleValue;  //usage of valueOf()
}
catch (NumberFormatException nfe) {
    nfe.printStackTrace();
}

解决方案 »

  1.   

    java.lang.Double是原始类型double对应的wraper类The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double. 具体什么时候用,就看你需要得到什么类型的结果了
      

  2.   

    parseDouble(String s) 
              Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double.valueOf(String s) 
              Returns a Double object holding the double value represented by the argument string s.所以一个返回的是double类型数据,一个返回的是Double类型的对象!!
      

  3.   

    class TestD
    {
        public static void main(String [] args)
        {
            String s = "123.456";
            double d1=0;
            double d2=0;        try 
            {
                d1 = Double.parseDouble(s);  // usage of parseDouble()
                d2 = Double.valueOf(s).doubleValue();  //usage of valueOf()            System.out.println(d1);
                System.out.println(d2);
            }
            catch (NumberFormatException nfe) 
            {
                nfe.printStackTrace();
            }
        }
    }
    这里使用doubleValue(),再将Double对象的数据转换为double基本类型。