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 digitsSignedIntegerin exponent: 1 to 2 digitsFloatingPointLiteral: 1 to 14 characters, e.g. "-1.2345678E-38"
FloatingPointLiteralwith or without white space around it:Integer.MAX_VALUE- 4 = 2,147,483,643 characters.
-
Method Summary
Modifier and TypeMethodDescriptionstatic floatparseFloat(byte[] str) Convenience method for callingparseFloat(byte[], int, int).static floatparseFloat(byte[] str, int offset, int length) Parses aFloatingPointLiteralfrom abyte-Array and converts it into afloatvalue.static floatparseFloat(char[] str) Convenience method for callingparseFloat(char[], int, int).static floatparseFloat(char[] str, int offset, int length) Parses aFloatingPointLiteralfrom abyte-Array and converts it into afloatvalue.static floatparseFloat(CharSequence str) Convenience method for callingparseFloat(CharSequence, int, int).static floatparseFloat(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 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
-
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 aFloatingPointLiteralfrom abyte-Array and converts it into afloatvalue.- 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 aFloatingPointLiteralfrom abyte-Array and converts it into afloatvalue.- 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
-