code: public BigInteger toBigInteger(Object val) {
      if (val == null) {
        return BigInteger.ZERO;
      }
      else if (val instanceof BigInteger) {
        return (BigInteger) val;
      }
      else if (val instanceof Double) {
        if (!Double.isNaN(((Double) val).doubleValue())) {
          return new BigInteger(val.toString());
        }
        else {
          return BigInteger.ZERO;
        }
      }
      else if (val instanceof Number) {
        return new BigInteger(val.toString());
      }
      else if (val instanceof String) {
        String string = (String) val;
        if ("".equals(string.trim())) {
          return BigInteger.ZERO;
        }
        else {
          return new BigInteger(string);
        }
      }
      else if (val instanceof Character) {
        int i = ((Character) val).charValue();
        return BigInteger.valueOf(i);
      }
  
      throw new ArithmeticException("BigInteger coercion: " + val.getClass().getName() + ":(" + val + ")");
    }
docs: Get a BigInteger from the object passed. Null and empty string maps to
  zero.
  
  @param val
  the object to be coerced.
  @return a BigDecimal.
  @throws NullPointerException
  if val is null and mode is strict.