Double.parseDouble("-1.23E-3") = -1.23E-3

解决方案 »

  1.   

    class Test
    {
        public static void main(String args[])
        {
            System.out.println(Double.parseDouble("-1.23E-3"));
        }
    } //输出
    -0.00123
      

  2.   

    import java.util.*;
    import java.text.DecimalFormat;
    public class Change {  
    public static void main(String[] args) throws Exception{  DecimalFormat df = new DecimalFormat("#.00");
        double a = 1111111111.11;
        double b = 1111111111.11;
        String ab = df.format(a + b);
        
        System.out.println(ab);
        System.out.println("科学计数法:"+(a+b));
        
    }  
    }
      

  3.   

    class Test
    {
        public static void main(String args[])
        {
            System.out.println(Double.parseDouble("-1.23E-3"));
            System.out.println( (new Double("-1.23E-3")).toString() );
        }
    } //输出
    -0.00123
    -0.00123
      

  4.   

    改成"-1.23E-12"看看
    class Test
    {
        public static void main(String args[])
        {
            System.out.println(Double.parseDouble("-1.23E-12"));
            System.out.println( (new Double("-1.23E-12")).toString() );
        }
    } //输出
    -1.23E-12
    -1.23E-12
      

  5.   

    DecimalFormat df = new DecimalFormat("#.0000");
    double d = 12345678.12345;
    String dStr = df.format(d);
    这样dStr就变成了:1234567.1234,而不会是:1.234567812345E7 的形式了。
      

  6.   

    用DecimalFormat是可以的,对于有多少位小数处理一下format就可以了。
    但是这些输出都是String对象。如果转换成double数据,又会变成原来一样了:(
      

  7.   

    public String floatFormat(double value)
    {
         try
    {
             double newValue = value;
         String newValueStr = String.valueOf(newValue);
         int eindex = newValueStr.toUpperCase().indexOf("E");
         String format = "";
         if(eindex == -1)
         {
         return newValueStr;
         }
         else
         {
         String cardinalNumberStr =  newValueStr.substring(0,eindex);
         String exponentialStr = newValueStr.substring(eindex + 1);
         if(exponentialStr.startsWith("+"))
         {
         exponentialStr = exponentialStr.substring(1);
         }
         int exponential = Integer.parseInt(exponentialStr);
         if(exponential > 0)
         {
         if((cardinalNumberStr.length() - 2 - exponential) > 0)
         {
         format = "#.";
         for(int i=0; i<(cardinalNumberStr.length() - 2 - exponential); i++)
         {
         format += 0;
         }
         }
         else
         {
         format = "#.0";
         }
         }
         else if(exponential < 0)
         {
         format = "0.";
        
         for(int i=0; i<(cardinalNumberStr.substring(cardinalNumberStr.indexOf(".") + 1).length() - exponential); i++)
         {
         format += 0;
         }
         }
         else
         {
         format = "#.0";
         }
         if(format.length() == 2)
         {
         format += 0;
         }
         DecimalFormat df = new DecimalFormat(format);
         return df.format(newValue);
         }
         }
         catch(Exception e)
    {
         e.printStackTrace();
         return String.valueOf(value);
         }
        }