我需要把String类型的数据转换为double型进行运算,该怎么转?

解决方案 »

  1.   

    String   s="213213123.231321";   
      double   d=Double.parseDouble(s); 
      

  2.   


    String str = "3.3";
    double b;
    try{
         b=Double.parseDouble(str);
    }catch(Excption e){}
      

  3.   


    String str="3.3";double b;try{
         b=Double.parseDouble(str);
    }catch(Exception e){}上面Exception少写了一个e了
      

  4.   


    这个, 验证的操作应该在转换之前做好,不该去抓exception了 ps:
       楼主的题不值20分啊,呵呵
      

  5.   

    楼上说的都对。也可以这样写 double d=new Double(s).doubleValue();
      

  6.   

    double  d=Double.parseDouble(s)其他的都在前面改double为float或Integer
      

  7.   

    double d = Double.parseDouble(s);
    有 public static Double parseDouble(String s) throws NumberFomatException
      

  8.   

    public class StringToOther { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("哈哈哈");

    String s = "100";
    int is = Integer.parseInt(s);
    printOut(is);

    double ds = Double.parseDouble(s);
    printOut(ds);

    boolean bs = Boolean.parseBoolean(s);
    printOut(bs);//不是1就是false

    char[] charS = s.toCharArray();
    printOut(charS);

    byte[] byteS = s.getBytes();
    printOut(byteS);

    short shortS = Short.parseShort(s);
    printOut(shortS);

    long longS = Long.parseLong(s);
    printOut(longS);
    }
    private static void printOut(Object o){
    System.out.println(o);
    }
    private static void printOut(char[] chs){
    for(int i = 0;i<chs.length;i++)
    System.out.print(chs[i]);
    System.out.println();
    }
    private static void printOut(byte[] bs){
    for(int i = 0;i<bs.length;i++){
    System.out.print((char)bs[i]);//byte 是?
    }
    System.out.println();
    }
    }
      

  9.   

    每个基本类型都有一个封装类
    char,byte,short,int,long,float,double对应
    Char,Byte,Short,Integer,Long,Float,Double
    都对应一个解析String到对应基本类型的类方法:parse***char c= Char.parseChar(str)
    byte b = Byte.parseByte(str)
    short s =Short.parseShort(str)int i= Integer.parseInt(str)
    long l = Long.parseLong(str)
    Float f =Float.parseFloat(str)
    double d =Double.parseDouble(str)每个str都判断非null非""
      

  10.   

    string s;
    double d;
    s="1.41";
    d=Double.parseDouble(s);
      

  11.   

    这个问题查查API很容易解决的。
      

  12.   

    try {
     
      double d = Double.parseDouble(str) ;
    }catch(Exception e) {}
      

  13.   

    String str = "3.3";
    double b;
    try{
         b=Double.parseDouble(str.trim());
    }catch(Excption e){
         System.out.println("不是一个数字字符串!");
    }
      

  14.   

    String str="3.3";double b;try{
         b=Double.parseDouble(str);
    }catch(Exception e){}
    up
      

  15.   

    就一句
    Double parseDouble(String s)
      

  16.   

    String s=" " // your target value
    double d=Double.parseDouble(s); // the result这个不是checked exception   可以不用try-catch block
      

  17.   

    String   s="3.123";   
    double   d;
    d=Double.parseDouble(s);
      

  18.   

    Double.parseDouble(s);
    或者  new Double(s).doubleValue()
      

  19.   

    JDK API 中很容易就可以找到各种类型的转换方法!
      

  20.   

    应该学会用API,不要因为这些小问题就去问人吖,查API就行了~~