public static String DoubletoEstring(double num,int w,int d){
  boolean minusf=false;
  boolean minuse=false;
  String snum;
  if (Double.isNaN(num)) {
    snum="NaN";
  }
 else   if (Double.isInfinite(num)) {
    snum="Infty";
  }
 else   if (num == 0.0) {
    snum="e+00";
    for (int i=0; i < d; i++)     snum="0" + snum;
    snum="0." + snum;
  }
 else {
    if (num < 0) {
      minusf=true;
      num=-num;
    }
    int exp=(int)(Math.log(num) / Math.log(10.0));
    if (num < 1) {
      exp=exp - 1;
    }
    double frac=num / Math.pow(10,exp);
    if (frac > 10. - Math.pow(10.,-d)) {
      frac=frac / 10;
      exp=exp + 1;
    }
    fmt.setMaximumFractionDigits(d);
    fmt.setMinimumFractionDigits(d);
    fmt.setGroupingUsed(false);
    String sfrac=fmt.format(frac);
    if (exp < 0) {
      minuse=true;
      exp=-exp;
    }
    String sexp=Integer.toString(exp);
    snum=sexp;
    if (snum.length() < 2)     snum="0" + snum;
    if (minuse)     snum="e-" + snum;
 else     snum="e+" + snum;
    snum=sfrac + snum;
    if (minusf)     snum="-" + snum;
  }
  while (snum.length() < w)   snum=" " + snum;
  return snum;
}

public static String DoubletoEstring ( double num , int w , int d ) { boolean minusf = false ; boolean minuse = false ; String snum ; if ( Double . isNaN ( num ) ) { snum = "NaN" ; } else if ( Double . isInfinite ( num ) ) { snum = "Infty" ; } else if ( num == 0.0 ) { snum = "e+00" ; for ( int i = 0 ; i < d ; i ++ ) snum = "0" + snum ; snum = "0." + snum ; } else { if ( num < 0 ) { minusf = true ; num = - num ; } int exp = ( int ) ( Math . log ( num ) / Math . log ( 10.0 ) ) ; if ( num < 1 ) { exp = exp - 1 ; } double frac = num / Math . pow ( 10 , exp ) ; if ( frac > 10. - Math . pow ( 10. , - d ) ) { frac = frac / 10 ; exp = exp + 1 ; } fmt . setMaximumFractionDigits ( d ) ; fmt . setMinimumFractionDigits ( d ) ; fmt . setGroupingUsed ( false ) ; String sfrac = fmt . format ( frac ) ; if ( exp < 0 ) { minuse = true ; exp = - exp ; } String sexp = Integer . toString ( exp ) ; snum = sexp ; if ( snum . length ( ) < 2 ) snum = "0" + snum ; if ( minuse ) snum = "e-" + snum ; else snum = "e+" + snum ; snum = sfrac + snum ; if ( minusf ) snum = "-" + snum ; } while ( snum . length ( ) < w ) snum = " " + snum ; return snum ; }
converts a double to w . d e format .
