Class JavaBigDecimalParser


  • public final class JavaBigDecimalParser
    extends java.lang.Object
    Parses a BigDecimal value; the supported syntax is compatible with BigDecimal(String).

    Syntax

    Parses a BigDecimalString that is compatible with the grammar specified in BigDecimal(String).

    Formal specification of the grammar:

    BigDecimalString:
    [Sign] Significand [Exponent]
    Sign:
    +
    -
    Significand:
    IntegerPart . [FractionPart]
    . FractionPart
    IntegerPart
    IntegerPart:
    Digits
    FractionPart:
    Digits
    DecExponent:
    ExponentIndicator SignedInteger
    ExponentIndicator:
    e
    E
    SignedInteger:
    [Sign] Digits
    Digits:
    Digit {Digit}

    Character lengths accepted by BigInteger(String):

    • BigDecimalString: Integer.MAX_VALUE - 4.

      The resulting value must fit into 2^31 - 1 bits. The decimal representation of the value 2^31 - 1 has 646,456,993 digits. Therefore an input String can only contain up to that many significant digits - the remaining digits must be leading zeroes.

    • SignedInteger in exponent: 1 to 10 digits. Exponents with more digits would yield to a BigDecimal.scale() that does not fit into a int-value.
    • BigDecimalString: 1 to 1,292,782,621+4+10=1,292,782,635 characters, e.g. "-1.234567890....12345E-2147483647".

    References:

    Java SE 17 & JDK 17, JavaDoc, Class BigDecimal
    docs.oracle.com
    • Constructor Detail

      • JavaBigDecimalParser

        private JavaBigDecimalParser()
        Don't let anyone instantiate this class.
    • Method Detail

      • parseBigDecimal

        public static java.math.BigDecimal parseBigDecimal​(java.lang.CharSequence str)
                                                    throws java.lang.NumberFormatException
        Convenience method for calling parseBigDecimal(CharSequence, int, int).
        Parameters:
        str - the string to be parsed
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseBigDecimal

        public static java.math.BigDecimal parseBigDecimal​(java.lang.CharSequence str,
                                                           int offset,
                                                           int length)
                                                    throws java.lang.NumberFormatException
        Parses a FloatingPointLiteral from a CharSequence and converts it into a BigDecimal value.
        Parameters:
        str - the string to be parsed
        offset - the start offset of the FloatingPointLiteral in str
        length - the length of FloatingPointLiteral in str
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseBigDecimal

        public static java.math.BigDecimal parseBigDecimal​(byte[] str)
                                                    throws java.lang.NumberFormatException
        Convenience method for calling parseBigDecimal(byte[], int, int).
        Parameters:
        str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseBigDecimal

        public static java.math.BigDecimal parseBigDecimal​(byte[] str,
                                                           int offset,
                                                           int length)
                                                    throws java.lang.NumberFormatException
        Parses a FloatingPointLiteral from a byte-Array and converts it into a BigDecimal value.
        Parameters:
        str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
        offset - The index of the first byte to parse
        length - The number of bytes to parse
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseBigDecimal

        public static java.math.BigDecimal parseBigDecimal​(char[] str)
                                                    throws java.lang.NumberFormatException
        Convenience method for calling parseBigDecimal(char[], int, int).
        Parameters:
        str - the string to be parsed
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseBigDecimal

        public static java.math.BigDecimal parseBigDecimal​(char[] str,
                                                           int offset,
                                                           int length)
                                                    throws java.lang.NumberFormatException
        Parses a FloatingPointLiteral from a byte-Array and converts it into a double value.

        See JavaBigDecimalParser for the syntax of FloatingPointLiteral.

        Parameters:
        str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
        offset - The index of the first character to parse
        length - The number of characters to parse
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully