public static Number toNumber(String str,Number defaultValue){
  try {
    if (str.indexOf('.') != -1) {
      return new BigDecimal(str);
    }
    BigInteger bi=new BigInteger(str);
    int l=bi.bitLength();
    if (l < 32)     return new Integer(bi.intValue());
    if (l < 64)     return new Long(bi.longValue());
    return bi;
  }
 catch (  Throwable t) {
    return defaultValue;
  }
}

public static Number toNumber ( String str , Number defaultValue ) { try { if ( str . indexOf ( '.' ) != - 1 ) { return new BigDecimal ( str ) ; } BigInteger bi = new BigInteger ( str ) ; int l = bi . bitLength ( ) ; if ( l < 32 ) return new Integer ( bi . intValue ( ) ) ; if ( l < 64 ) return new Long ( bi . longValue ( ) ) ; return bi ; } catch ( Throwable t ) { return defaultValue ; } }
returns a number object , this can be a bigdecimal , biginteger , long , double , depending on the input .
