Top Description Fields Constructors Methods
ch.randelshofer.fastdoubleparser

public Class JavaBigDecimalParser

extends Object
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger

Parses a BigDecimal value; the supported syntax is compatible with BigDecimal#BigDecimal(String).

Syntax

Parses a BigDecimalString that is compatible with the grammar specified in BigDecimal#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#BigInteger(String):

Maximal input length supported by this parser:

References:

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

Field Summary

Modifier and TypeField and Description
private static final JavaBigDecimalFromByteArray
private static final JavaBigDecimalFromCharArray
private static final JavaBigDecimalFromCharSequence

Constructor Summary

AccessConstructor and Description
private
JavaBigDecimalParser()

Don't let anyone instantiate this class.

Method Summary

Modifier and TypeMethod and Description
public static BigDecimal

Returns:

the parsed value
parseBigDecimal
(CharSequence
the string to be parsed
str
)

Convenience method for calling parseBigDecimal(CharSequence, int, int).

public static BigDecimal

Returns:

the parsed value
parseBigDecimal
(CharSequence
the string to be parsed
str
,
int
the start offset of the FloatingPointLiteral in str
offset
,
int
the length of FloatingPointLiteral in str
length
)

Parses a FloatingPointLiteral from a CharSequence and converts it into a BigDecimal value.

public static BigDecimal

Returns:

the parsed value
parseBigDecimal
(byte[]
the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
str
)

Convenience method for calling parseBigDecimal(byte[], int, int).

public static BigDecimal

Returns:

the parsed value
parseBigDecimal
(byte[]
the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
str
,
int
The index of the first byte to parse
offset
,
int
The number of bytes to parse
length
)

Parses a FloatingPointLiteral from a byte-Array and converts it into a BigDecimal value.

public static BigDecimal

Returns:

the parsed value
parseBigDecimal
(char[]
the string to be parsed
str
)

Convenience method for calling parseBigDecimal(char[], int, int).

public static BigDecimal

Returns:

the parsed value
parseBigDecimal
(char[]
the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
str
,
int
The index of the first character to parse
offset
,
int
The number of characters to parse
length
)

Parses a FloatingPointLiteral from a byte-Array and converts it into a double value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTE_ARRAY_PARSERback to summary
private static final JavaBigDecimalFromByteArray BYTE_ARRAY_PARSER
CHAR_ARRAY_PARSERback to summary
private static final JavaBigDecimalFromCharArray CHAR_ARRAY_PARSER
CHAR_SEQUENCE_PARSERback to summary
private static final JavaBigDecimalFromCharSequence CHAR_SEQUENCE_PARSER

Constructor Detail

JavaBigDecimalParserback to summary
private JavaBigDecimalParser()

Don't let anyone instantiate this class.

Method Detail

parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(CharSequence str) throws NumberFormatException

Convenience method for calling parseBigDecimal(CharSequence, int, int).

Parameters
str:CharSequence

the string to be parsed

Returns:BigDecimal

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(CharSequence str, int offset, int length) throws NumberFormatException

Parses a FloatingPointLiteral from a CharSequence and converts it into a BigDecimal value.

Parameters
str:CharSequence

the string to be parsed

offset:int

the start offset of the FloatingPointLiteral in str

length:int

the length of FloatingPointLiteral in str

Returns:BigDecimal

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
IllegalArgumentException:
if offset or length are illegal
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(byte[] str) throws NumberFormatException

Convenience method for calling parseBigDecimal(byte[], int, int).

Parameters
str:byte[]

the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding

Returns:BigDecimal

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(byte[] str, int offset, int length) throws NumberFormatException

Parses a FloatingPointLiteral from a byte-Array and converts it into a BigDecimal value.

Parameters
str:byte[]

the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding

offset:int

The index of the first byte to parse

length:int

The number of bytes to parse

Returns:BigDecimal

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
IllegalArgumentException:
if offset or length are illegal
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(char[] str) throws NumberFormatException

Convenience method for calling parseBigDecimal(char[], int, int).

Parameters
str:char[]

the string to be parsed

Returns:BigDecimal

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
parseBigDecimalback to summary
public static BigDecimal parseBigDecimal(char[] str, int offset, int length) throws NumberFormatException

Parses a FloatingPointLiteral from a byte-Array and converts it into a double value.

See JavaBigDecimalParser for the syntax of FloatingPointLiteral.

Parameters
str:char[]

the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding

offset:int

The index of the first character to parse

length:int

The number of characters to parse

Returns:BigDecimal

the parsed value

Exceptions
NumberFormatException:
if the string can not be parsed successfully
NullPointerException:
if the string is null
IllegalArgumentException:
if offset or length are illegal