@ Nonnull public BigDecimal toBigDecimal ( ) { int scale = 0 ; String text = getIntegerPart ( ) ; String t_fraction = getFractionalPart ( ) ; if ( t_fraction != null ) { text += getFractionalPart ( ) ; // XXX Wrong for anything but base 10. scale += t_fraction . length ( ) ; } String t_exponent = getExponent ( ) ; if ( t_exponent != null ) scale -= Integer . parseInt ( t_exponent ) ; BigInteger unscaled = new BigInteger ( text , getBase ( ) ) ; return new BigDecimal ( unscaled , scale ) ; }
So it turns out that parsing arbitrary bases into arbitrary precision numbers is nontrivial and this routine gets it wrong in many important cases .