private static BigInteger convertBigDecimalToBigInteger(BigDecimal d)
     throws NumberFormatException {
   try {
     return d.toBigIntegerExact();
   } catch (ArithmeticException e) {
     NumberFormatException nfe =
         new NumberFormatException("Cannot represent BigDecimal " + d + " as BigInteger");
     nfe.initCause(e);
     throw nfe;
   }
 }
Ejemplo n.º 2
0
  /**
   * Returns the unsigned {@code int} value represented by the given string.
   *
   * <p>Accepts a decimal, hexadecimal, or octal number given by specifying the following prefix:
   *
   * <ul>
   *   <li>{@code 0x}<i>HexDigits</i>
   *   <li>{@code 0X}<i>HexDigits</i>
   *   <li>{@code #}<i>HexDigits</i>
   *   <li>{@code 0}<i>OctalDigits</i>
   * </ul>
   *
   * @throws NumberFormatException if the string does not contain a valid unsigned {@code int} value
   * @since 13.0
   */
  public static int decode(String stringValue) {
    ParseRequest request = ParseRequest.fromString(stringValue);

    try {
      return parseUnsignedInt(request.rawValue, request.radix);
    } catch (NumberFormatException e) {
      NumberFormatException decodeException =
          new NumberFormatException("Error parsing value: " + stringValue);
      decodeException.initCause(e);
      throw decodeException;
    }
  }