public static Number convertToNumber(String str){
  if (str == null) {
    return null;
  }
  str=str.trim();
  if (str.length() == 0) {
    return null;
  }
  if (str.indexOf('.') >= 0 || str.indexOf('e') >= 0 || str.indexOf('E') >= 0) {
    return Double.valueOf(str);
  }
  try {
    long lval=Long.parseLong(str);
    if (lval == (int)lval) {
      return new Integer((int)lval);
    }
    return new Long(lval);
  }
 catch (  NumberFormatException ee) {
    return new java.math.BigInteger(str,10);
  }
}

public static Number convertToNumber ( String str ) { if ( str == null ) { return null ; } str = str . trim ( ) ; if ( str . length ( ) == 0 ) { return null ; } if ( str . indexOf ( '.' ) >= 0 || str . indexOf ( 'e' ) >= 0 || str . indexOf ( 'E' ) >= 0 ) { return Double . valueOf ( str ) ; } try { long lval = Long . parseLong ( str ) ; if ( lval == ( int ) lval ) { return new Integer ( ( int ) lval ) ; } return new Long ( lval ) ; } catch ( NumberFormatException ee ) { return new java . math . BigInteger ( str , 10 ) ; } }
if str is null , empty , or blank , returns null . otherwise , return a double if str spells a double value and contains ' . ' or ' e ' . otherwise , return an integer if str spells an int value . otherwise , return a long if str spells a long value . otherwise , return a biginteger for the string . otherwise , throw numberformatexception .
