public static double parse(String s){
  try {
    return Double.parseDouble(s);
  }
 catch (  NumberFormatException e) {
  }
  s=s.replaceAll(",",".");
  s=s.replaceAll("\u00BC",".25");
  s=s.replaceAll("\u00BD",".5");
  s=s.replaceAll("\u00BE",".75");
  try {
    return Double.parseDouble(s);
  }
 catch (  NumberFormatException e) {
  }
  Pattern p2=Pattern.compile("[^0-9]*([[0-9.]\\.]+)\\s?-\\s?([[0-9]\\.]+)(.*)");
  Matcher m2=p2.matcher(s);
  if (m2.matches()) {
    try {
      return (Double.parseDouble(m2.group(1)) + Double.parseDouble(m2.group(2))) / 2;
    }
 catch (    NumberFormatException e) {
    }
  }
  Pattern p1=Pattern.compile("[^0-9]*([[0-9]\\.]+)(.*)");
  Matcher m1=p1.matcher(s);
  if (m1.matches()) {
    try {
      return Double.parseDouble(m1.group(1));
    }
 catch (    NumberFormatException e) {
    }
  }
  return Double.NaN;
}

public static double parse ( String s ) { try { return Double . parseDouble ( s ) ; } catch ( NumberFormatException e ) { } s = s . replaceAll ( "," , "." ) ; s = s . replaceAll ( "¼" , ".25" ) ; s = s . replaceAll ( "½" , ".5" ) ; s = s . replaceAll ( "¾" , ".75" ) ; try { return Double . parseDouble ( s ) ; } catch ( NumberFormatException e ) { } Pattern p2 = Pattern . compile ( "[^0-9]*([[0-9.]\\.]+)\\s?-\\s?([[0-9]\\.]+)(.*)" ) ; Matcher m2 = p2 . matcher ( s ) ; if ( m2 . matches ( ) ) { try { return ( Double . parseDouble ( m2 . group ( 1 ) ) + Double . parseDouble ( m2 . group ( 2 ) ) ) / 2 ; } catch ( NumberFormatException e ) { } } Pattern p1 = Pattern . compile ( "[^0-9]*([[0-9]\\.]+)(.*)" ) ; Matcher m1 = p1 . matcher ( s ) ; if ( m1 . matches ( ) ) { try { return Double . parseDouble ( m1 . group ( 1 ) ) ; } catch ( NumberFormatException e ) { } } return Double . NaN ; }
parse a number possibly surrounded by other information .
