code: public static String doubleToString(double d) {
          if (Double.isInfinite(d) || Double.isNaN(d)) {
              return "null";
          }
  
  // Shave off trailing zeros and decimal point, if possible.
  
          String string = Double.toString(d);
          if (string.indexOf('.') > 0 && string.indexOf('e') < 0
                  && string.indexOf('E') < 0) {
              while (string.endsWith("0")) {
                  string = string.substring(0, string.length() - 1);
              }
              if (string.endsWith(".")) {
                  string = string.substring(0, string.length() - 1);
              }
          }
          return string;
      }
docs: Produce a string from a double. The string "null" will be returned if the
  number is not finite.
  
  @param d
  A double.
  @return A String.