Package ch.randelshofer.fastdoubleparser
Class JavaFloatParser
java.lang.Object
ch.randelshofer.fastdoubleparser.JavaFloatParser
Parses a
float
value; the supported syntax is compatible with
Float.valueOf(String)
.
See JavaDoubleParser
for a description of the supported grammar.
Expected character lengths for values produced by Float.toString(float)
:
DecSignificand
(IntegerPart
+FractionPart
): 1 to 8 digitsIntegerPart
: 1 to 7 digitsFractionPart
: 1 to 7 digitsSignedInteger
in exponent: 1 to 2 digitsFloatingPointLiteral
: 1 to 14 characters, e.g. "-1.2345678E-38"
FloatingPointLiteral
with or without white space around it:Integer.MAX_VALUE
- 4 = 2,147,483,643 characters.
-
Method Summary
Modifier and TypeMethodDescriptionstatic float
parseFloat
(byte[] str) Convenience method for callingparseFloat(byte[], int, int)
.static float
parseFloat
(byte[] str, int offset, int length) Parses aFloatingPointLiteral
from abyte
-Array and converts it into afloat
value.static float
parseFloat
(char[] str) Convenience method for callingparseFloat(char[], int, int)
.static float
parseFloat
(char[] str, int offset, int length) Parses aFloatingPointLiteral
from abyte
-Array and converts it into afloat
value.static float
parseFloat
(CharSequence str) Convenience method for callingparseFloat(CharSequence, int, int)
.static float
parseFloat
(CharSequence str, int offset, int length)
-
Method Details
-
parseFloat
Convenience method for callingparseFloat(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
-
parseFloat
public static float parseFloat(CharSequence str, int offset, int length) throws NumberFormatException - Parameters:
str
- the string to be parsedoffset
- the start offset of theFloatingPointLiteral
instr
length
- the length ofFloatingPointLiteral
instr
- 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
-
parseFloat
Convenience method for callingparseFloat(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
-
parseFloat
Parses aFloatingPointLiteral
from abyte
-Array and converts it into afloat
value.- 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
-
parseFloat
Convenience method for callingparseFloat(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
-
parseFloat
Parses aFloatingPointLiteral
from abyte
-Array and converts it into afloat
value.- 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
-