double (String s) { try { return Double.parseDouble(s); } catch (NumberFormatException e) { int begin = 0; int end = -1; for (int i = s.length(); --i >= 0;) { final char c = s.charAt(i); final boolean isDigit = '0' <= c && c <= '9' || c == '.'; if (isDigit) { if (end == -1) { end = i + 1; } begin = i; } else { if (end == -1) continue; break; } } if (end == -1) return 0.0; try { return Double.parseDouble(s.substring(begin, end)); } catch (NumberFormatException e1) { return 0.0; } } }