Class JavaFloatParser


  • public final class JavaFloatParser
    extends java.lang.Object
    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 digits
    • IntegerPart: 1 to 7 digits
    • FractionPart: 1 to 7 digits
    • SignedInteger in exponent: 1 to 2 digits
    • FloatingPointLiteral: 1 to 14 characters, e.g. "-1.2345678E-38"
    Maximal input length supported by this parser:
    • FloatingPointLiteral with or without white space around it: Integer.MAX_VALUE - 4 = 2,147,483,643 characters.
    • Constructor Detail

      • JavaFloatParser

        private JavaFloatParser()
        Don't let anyone instantiate this class.
    • Method Detail

      • parseFloat

        public static float parseFloat​(java.lang.CharSequence str)
                                throws java.lang.NumberFormatException
        Convenience method for calling parseFloat(CharSequence, int, int).
        Parameters:
        str - the string to be parsed
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseFloat

        public static float parseFloat​(java.lang.CharSequence str,
                                       int offset,
                                       int length)
                                throws java.lang.NumberFormatException
        Parses a FloatingPointLiteral from a CharSequence and converts it into a float value.
        Parameters:
        str - the string to be parsed
        offset - the start offset of the FloatingPointLiteral in str
        length - the length of FloatingPointLiteral in str
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseFloat

        public static float parseFloat​(byte[] str)
                                throws java.lang.NumberFormatException
        Convenience method for calling parseFloat(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 null
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseFloat

        public static float parseFloat​(byte[] str,
                                       int offset,
                                       int length)
                                throws java.lang.NumberFormatException
        Parses a FloatingPointLiteral from a byte-Array and converts it into a float value.
        Parameters:
        str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
        offset - The index of the first byte to parse
        length - The number of bytes to parse
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseFloat

        public static float parseFloat​(char[] str)
                                throws java.lang.NumberFormatException
        Convenience method for calling parseFloat(char[], int, int).
        Parameters:
        str - the string to be parsed
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.NumberFormatException - if the string can not be parsed successfully
      • parseFloat

        public static float parseFloat​(char[] str,
                                       int offset,
                                       int length)
                                throws java.lang.NumberFormatException
        Parses a FloatingPointLiteral from a byte-Array and converts it into a float value.
        Parameters:
        str - the string to be parsed, a byte array with characters in ISO-8859-1, ASCII or UTF-8 encoding
        offset - The index of the first character to parse
        length - The number of characters to parse
        Returns:
        the parsed value
        Throws:
        java.lang.NullPointerException - if the string is null
        java.lang.IllegalArgumentException - if offset or length are illegal
        java.lang.NumberFormatException - if the string can not be parsed successfully