java.lang.Object
ch.randelshofer.fastdoubleparser.JavaFloatParser

public class JavaFloatParser extends 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.
  • Method Details

    • parseFloat

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

      public static float parseFloat(CharSequence str, int offset, int length) throws 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:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseFloat

      public static float parseFloat(byte[] str) throws 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:
      NullPointerException - if the string is null
      NumberFormatException - if the string can not be parsed successfully
    • parseFloat

      public static float parseFloat(byte[] str, int offset, int length) throws 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:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully
    • parseFloat

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

      public static float parseFloat(char[] str, int offset, int length) throws 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:
      NullPointerException - if the string is null
      IllegalArgumentException - if offset or length are illegal
      NumberFormatException - if the string can not be parsed successfully