Results 1 to 3 of 3

Thread: FieldSet.readDouble for scientific numbers somehow fails / Bug?

  1. #1
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default FieldSet.readDouble for scientific numbers somehow fails / Bug?

    HI guys
    i just came across this today

    as part of our spring batch infrastructure, we are reading a file where sometimes numbers are specified like
    this

    1e-06

    When using FieldSet.readDouble() the above came back as 1.0

    could you kindly have a look pls?

    rgsd
    marco

  2. #2

    Default

    it's the wrong format for scientific notation, see Java API DecimalFormat (*)

    E Number Yes Separates mantissa and exponent in scientific notation. Need not be quoted in prefix or suffix.
    its big "E"

    the small "e" will just stop the parser after the 1, so you get 1.0, see parse api doc:


    parse

    public Number parse(String source)
    throws ParseException
    Parses text from the beginning of the given string to produce a number. The method may not use the entire text of the given string.
    See the parse(String, ParsePosition) method for more information on number parsing.

    Parameters:
    source - A String whose beginning should be parsed.
    Returns:
    A Number parsed from the string.
    Throws:
    ParseException - if the beginning of the specified string cannot be parsed.
    you can test this behaviour yourself with "1@" you get "1.0", so only the "1" is parsed successfully

    (*) Spring uses DefaultFieldSet internally and a Numberformat.getInstance(...) there, which will provide DecimalFormat

  3. #3
    Join Date
    Jul 2011
    Posts
    16

    Default

    Try using FieldSet.readString() instead of FieldSet.readDouble().
    Once you have read the string, you can construct a Double by passing the string as constructor argument.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •