Package ch.randelshofer.fastdoubleparser
Class JavaBigDecimalParser
- java.lang.Object
-
- ch.randelshofer.fastdoubleparser.JavaBigDecimalParser
-
public final class JavaBigDecimalParser extends java.lang.ObjectParses aBigDecimalvalue; the supported syntax is compatible withBigDecimal(String).Syntax
Parses a
BigDecimalStringthat is compatible with the grammar specified inBigDecimal(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 - 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 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
-
-
Field Summary
Fields Modifier and Type Field Description private static JavaBigDecimalFromByteArrayBYTE_ARRAY_PARSERprivate static JavaBigDecimalFromCharArrayCHAR_ARRAY_PARSERprivate static JavaBigDecimalFromCharSequenceCHAR_SEQUENCE_PARSER
-
Constructor Summary
Constructors Modifier Constructor Description privateJavaBigDecimalParser()Don't let anyone instantiate this class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.math.BigDecimalparseBigDecimal(byte[] str)Convenience method for callingparseBigDecimal(byte[], int, int).static java.math.BigDecimalparseBigDecimal(byte[] str, int offset, int length)Parses aFloatingPointLiteralfrom abyte-Array and converts it into aBigDecimalvalue.static java.math.BigDecimalparseBigDecimal(char[] str)Convenience method for callingparseBigDecimal(char[], int, int).static java.math.BigDecimalparseBigDecimal(char[] str, int offset, int length)Parses aFloatingPointLiteralfrom abyte-Array and converts it into adoublevalue.static java.math.BigDecimalparseBigDecimal(java.lang.CharSequence str)Convenience method for callingparseBigDecimal(CharSequence, int, int).static java.math.BigDecimalparseBigDecimal(java.lang.CharSequence str, int offset, int length)Parses aFloatingPointLiteralfrom aCharSequenceand converts it into aBigDecimalvalue.
-
-
-
Field Detail
-
BYTE_ARRAY_PARSER
private static final JavaBigDecimalFromByteArray BYTE_ARRAY_PARSER
-
CHAR_ARRAY_PARSER
private static final JavaBigDecimalFromCharArray CHAR_ARRAY_PARSER
-
CHAR_SEQUENCE_PARSER
private static final JavaBigDecimalFromCharSequence CHAR_SEQUENCE_PARSER
-
-
Method Detail
-
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(java.lang.CharSequence str) throws java.lang.NumberFormatExceptionConvenience method for callingparseBigDecimal(CharSequence, int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.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.NumberFormatExceptionParses aFloatingPointLiteralfrom aCharSequenceand converts it into aBigDecimalvalue.- Parameters:
str- the string to be parsedoffset- the start offset of theFloatingPointLiteralinstrlength- the length ofFloatingPointLiteralinstr- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(byte[] str) throws java.lang.NumberFormatExceptionConvenience 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:
java.lang.NullPointerException- if the string is nulljava.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.NumberFormatExceptionParses aFloatingPointLiteralfrom abyte-Array and converts it into aBigDecimalvalue.- 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:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(char[] str) throws java.lang.NumberFormatExceptionConvenience method for callingparseBigDecimal(char[], int, int).- Parameters:
str- the string to be parsed- Returns:
- the parsed value
- Throws:
java.lang.NullPointerException- if the string is nulljava.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.NumberFormatExceptionParses 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:
java.lang.NullPointerException- if the string is nulljava.lang.IllegalArgumentException- if offset or length are illegaljava.lang.NumberFormatException- if the string can not be parsed successfully
-
-