static BigDecimal toBigDecimal(Number n) {
        BigDecimal bd;
        if (n == null) {
            throw new IllegalArgumentException("Your number is null");
        } else if (n instanceof BigDecimal) {
            bd = (BigDecimal) n;
        } else if (n instanceof BigInteger) {
            bd = new BigDecimal((BigInteger) n);
        } else if (n instanceof Short
                || n instanceof Long
                || n instanceof Integer) {
            bd = BigDecimal.valueOf(n.longValue());
        } else if (n instanceof Float
                || n instanceof Double) {
            bd = BigDecimal.valueOf(n.doubleValue());
        } else {
            throw new IllegalArgumentException("Unsupported type:" + n);
        }
        return bd;
    }