String str = "1.0502487857251702E8";如何转成普通的数据表现形势,并且小数点后只保留两位,高手求教,在线等

解决方案 »

  1.   

    先根据E分割字符串,根据E后面的数据来截取前面的,然后转换成float后再乘上10 * E后面的数字大小
      

  2.   

    public void getDoubleValTest(){
    String str = "1.0502487857251702E8";
    String sarr[] = str.split("E");
    double res1 = Double.valueOf(sarr[0]);
    int ci = Integer.valueOf(sarr[1]);
    double cinum = 10;
    for(int i=0;i<ci;i++){
    cinum = cinum*10;
    }
    double res = res1*cinum;
    NumberFormat nf = new java.text.DecimalFormat("0.00");
    System.out.println("res:" + nf.format(res));
    }
      

  3.   

    res:1050248785.73,这个答案是不是多了一位啊?105024878.57 ? or 1050248785.73? 
      

  4.   

    String str = "1.0502487857251702E8";
    BigDecimal num = new BigDecimal(str);
    DecimalFormat df = new DecimalFormat("0.00");
    String res = df.format(num);
    System.out.println(res);