code: public static double atof(String s) {
          int i = 0;
          int sign = 1;
          double r = 0; // integer part
          double p = 1; // exponent of fractional part
          int state = 0; // 0 = int part, 1 = frac part
  
          while (i < s.length() && Character.isWhitespace(s.charAt(i)))
              i++;
          if (i < s.length() && s.charAt(i) == '-') {
              sign = -1;
              i++;
          } else if (i < s.length() && s.charAt(i) == '+') {
              i++;
          }
          while (i < s.length()) {
              char ch = s.charAt(i);
              if ('0' <= ch && ch <= '9') {
                  if (state == 0)
                      r = r * 10 + ch - '0';
                  else if (state == 1) {
                      p = p / 10;
                      r = r + p * (ch - '0');
                  }
              } else if (ch == '.') {
                  if (state == 0)
                      state = 1;
                  else
                      return sign * r;
              } else if (ch == 'e' || ch == 'E' || ch == 'd' || ch == 'D') {
                  long e = (int) parseLong(s.substring(i + 1), 10);
                  return sign * r * Math.pow(10, e);
              } else
                  return sign * r;
              i++;
          }
          return sign * r;
      }
docs: Converts a string of digits to an double.
  
  @param s a string denoting a double