public static java.lang.String toString(double d){
  double m=Math.abs(d);
  if (d == POSITIVE_INFINITY) {
    return "Infinity";
  }
 else   if (d == NEGATIVE_INFINITY) {
    return "-Infinity";
  }
 else   if (d == 0) {
    return "0.0";
  }
 else   if (m >= 1e-3 && m < 1e7) {
    String str=toStringImpl(d,false);
    char[] chars=str.toCharArray();
    int i=chars.length - 1;
    char c;
    while (i >= 0 && (c=chars[i]) == '0') {
      i--;
    }
    if (i < 0 || str.indexOf('.') == -1) {
      return str;
    }
 else     if (chars[i] == '.' || chars[i] == ',') {
      i++;
    }
    return str.substring(0,i + 1);
  }
 else {
    return toStringImpl(d,true);
  }
}

public static java . lang . String toString ( double d ) { double m = Math . abs ( d ) ; if ( d == POSITIVE_INFINITY ) { return "Infinity" ; } else if ( d == NEGATIVE_INFINITY ) { return "-Infinity" ; } else if ( d == 0 ) { return "0.0" ; } else if ( m >= 1e-3 && m < 1e7 ) { String str = toStringImpl ( d , false ) ; char [ ] chars = str . toCharArray ( ) ; int i = chars . length - 1 ; char c ; while ( i >= 0 && ( c = chars [ i ] ) == '0' ) { i -- ; } if ( i < 0 || str . indexOf ( '.' ) == - 1 ) { return str ; } else if ( chars [ i ] == '.' || chars [ i ] == ',' ) { i ++ ; } return str . substring ( 0 , i + 1 ) ; } else { return toStringImpl ( d , true ) ; } }
creates a string representation of the double argument . all characters mentioned below are ascii characters . if the argument is nan , the result is the string " nan " . otherwise , the result is a string that represents the sign and magnitude ( absolute value ) of the argument . if the sign is negative , the first character of the result is ' - ' ( ' - ' ) ; if the sign is positive , no sign character appears in the result . as for the magnitude : if is infinity , it is represented by the characters " infinity " ; thus , positive infinity produces the result " infinity " and negative infinity produces the result " - infinity " . if is zero , it is represented by the characters " 0 . 0 " ; thus , negative zero produces the result " - 0 . 0 " and positive zero produces the result " 0 . 0 " . if is greater than or equal to 10 - 3 but less than 107 , then it is represented as the integer part of , in decimal form with no leading zeroes , followed by ' . ' ( . ) , followed by one or more decimal digits representing the fractional part of . if is less than 10 - 3 or not less than 107 , then it is represented in so - called " computerized scientific notation . " let be the unique integer such that 10n = 10n + 1 ; then let be the mathematically exact quotient of and 10n so that 1 = 10 . the magnitude is then represented as the integer part of , as a single decimal digit , followed by ' . ' ( . ) , followed by decimal digits representing the fractional part of , followed by the letter ' e ' ( e ) , followed by a representation of as a decimal integer , as produced by the method . how many digits must be printed for the fractional part of m or a ? there must be at least one digit to represent the fractional part , and beyond that as many , but only as many , more digits as are needed to uniquely distinguish the argument value from adjacent values of type double . that is , suppose that x is the exact mathematical value represented by the decimal representation produced by this method for a finite nonzero argument d . then d must be the double value nearest to x ; or if two double values are equally close to x , then d must be one of them and the least significant bit of the significand of d must be 0 .
