Package ch.randelshofer.fastdoubleparser
Class JavaBigDecimalParser
java.lang.Object
ch.randelshofer.fastdoubleparser.JavaBigDecimalParser
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).
The range of the input values is limited as follows:
- The significand is limited to 536,870,919 digits.
- The exponent is limited to the range from
Integer.MIN_VALUE(exclusive) toInteger.MAX_VALUE(inclusive)
- 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):
Significand: 1 to 1,292,782,621 decimal digits.The resulting value must fit into
2^31 - 1bits. The decimal representation of the value2^31 - 1has 646,456,993 digits. Therefore an input String can only contain up to that many significant digits - the remaining digits must be leading zeroes.SignedIntegerin exponent: 1 to 10 digits. Exponents with more digits would yield to aBigDecimal.scale()that does not fit into aint-value.BigDecimalString: 1 to 536_870_919+4+10=536_870_933 characters, e.g. "-1.234567890....12345E-2147483647"
References:
- Java SE 17 & JDK 17, JavaDoc, Class BigDecimal
- docs.oracle.com
-
Method Summary
Modifier and TypeMethodDescriptionstatic BigDecimalparallelParseBigDecimal(byte[] str) Convenience method for callingparallelParseBigDecimal(byte[], int, int).static BigDecimalparallelParseBigDecimal(byte[] str, int offset, int length) static BigDecimalparallelParseBigDecimal(char[] str) Convenience method for callingparallelParseBigDecimal(char[], int, int).static BigDecimalparallelParseBigDecimal(char[] str, int offset, int length) Parses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.static BigDecimalConvenience method for callingparallelParseBigDecimal(CharSequence, int, int).static BigDecimalparallelParseBigDecimal(CharSequence str, int offset, int length) static BigDecimalparseBigDecimal(byte[] str) Convenience method for callingparseBigDecimal(byte[], int, int).static BigDecimalparseBigDecimal(byte[] str, int offset, int length) static BigDecimalparseBigDecimal(char[] str) Convenience method for callingparseBigDecimal(char[], int, int).static BigDecimalparseBigDecimal(char[] str, int offset, int length) Parses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.static BigDecimalConvenience method for callingparseBigDecimal(CharSequence, int, int).static BigDecimalparseBigDecimal(CharSequence str, int offset, int length)
-
Method Details
-
parseBigDecimal
Convenience method for callingparseBigDecimal(CharSequence, int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullNumberFormatException- if the string can not be parsed successfully
-
parseBigDecimal
public static BigDecimal parseBigDecimal(CharSequence str, int offset, int length) throws NumberFormatException - Parameters:
str- the string to be parsedoffset- the start offset of theFloatingPointLiteralinstrlength- the length ofFloatingPointLiteralinstr- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullIllegalArgumentException- if offset or length are illegalNumberFormatException- if the string can not be parsed successfully
-
parseBigDecimal
Convenience method for callingparseBigDecimal(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:
NullPointerException- if the string is nullNumberFormatException- if the string can not be parsed successfully
-
parseBigDecimal
public static BigDecimal parseBigDecimal(byte[] str, int offset, int length) throws NumberFormatException - Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset- The index of the first byte to parselength- The number of bytes to parse- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullIllegalArgumentException- if offset or length are illegalNumberFormatException- if the string can not be parsed successfully
-
parseBigDecimal
Convenience method for callingparseBigDecimal(char[], int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullNumberFormatException- if the string can not be parsed successfully
-
parseBigDecimal
public static BigDecimal parseBigDecimal(char[] str, int offset, int length) throws NumberFormatException Parses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.See
JavaBigDecimalParserfor the syntax ofFloatingPointLiteral.- Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset- The index of the first character to parselength- The number of characters to parse- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullIllegalArgumentException- if offset or length are illegalNumberFormatException- if the string can not be parsed successfully
-
parallelParseBigDecimal
Convenience method for callingparallelParseBigDecimal(CharSequence, int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullNumberFormatException- if the string can not be parsed successfully
-
parallelParseBigDecimal
public static BigDecimal parallelParseBigDecimal(CharSequence str, int offset, int length) throws NumberFormatException - Parameters:
str- the string to be parsedoffset- the start offset of theFloatingPointLiteralinstrlength- the length ofFloatingPointLiteralinstr- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullIllegalArgumentException- if offset or length are illegalNumberFormatException- if the string can not be parsed successfully
-
parallelParseBigDecimal
Convenience method for callingparallelParseBigDecimal(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:
NullPointerException- if the string is nullNumberFormatException- if the string can not be parsed successfully
-
parallelParseBigDecimal
public static BigDecimal parallelParseBigDecimal(byte[] str, int offset, int length) throws NumberFormatException - Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset- The index of the first byte to parselength- The number of bytes to parse- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullIllegalArgumentException- if offset or length are illegalNumberFormatException- if the string can not be parsed successfully
-
parallelParseBigDecimal
Convenience method for callingparallelParseBigDecimal(char[], int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullNumberFormatException- if the string can not be parsed successfully
-
parallelParseBigDecimal
public static BigDecimal parallelParseBigDecimal(char[] str, int offset, int length) throws NumberFormatException Parses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.See
JavaBigDecimalParserfor the syntax ofFloatingPointLiteral.- Parameters:
str- the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encodingoffset- The index of the first character to parselength- The number of characters to parse- Returns:
- the parsed value
- Throws:
NullPointerException- if the string is nullIllegalArgumentException- if offset or length are illegalNumberFormatException- if the string can not be parsed successfully
-