Results 1 to 8 of 8

Thread: formatting decimal values in fixed length file output

  1. #1
    Join Date
    Dec 2008
    Location
    Nashville, TN, USA
    Posts
    9

    Thumbs down formatting decimal values in fixed length file output

    I've been trying to find out how to format a decimal value into a fixed length file output such that leading zeroes are replaced with spaces. For example, given a double value of 21.5, I want the result to be a string that looks like this:
    " 21.50" (one leading space). Similarly, if the value is 1.5, I want the result to be " 1.50" (2 leading spaces)
    Have done some research and tried DecimalFormat from java.text, but haven't found a way to get the desired result. Any help would be much appreciated. Thanks

  2. #2
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    What version of Spring Batch are you using? This was something we recognized and fixed in 2.0.

  3. #3
    Join Date
    Dec 2008
    Location
    Nashville, TN, USA
    Posts
    9

    Smile

    We are currently using 1.1.3.RELEASE-A and the decisions concerning what software/what version are not in my hands. I have to convince the project manager before a change can be made. What benefits would we see, other than this specific issue?

  4. #4
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    The latest version of the docs contain a 'What's new in 2.0' section, but they haven't been pushed to the site yet. (mvn site in the docs directory will generate them for you if you like) Dave also wrote a blog post a couple of months ago highlighting the main themes:

    http://blog.springsource.com/2008/10...ature-rundown/

    It's not an exhaustive list, but its a pretty reasonable summary.

  5. #5
    Join Date
    Dec 2008
    Location
    Nashville, TN, USA
    Posts
    9

    Default

    Looking at the Spring Batch download area, it appears 2.0 is not a GA release, yet. How stable is it?

  6. #6
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I would say it's pretty stable. We plan to release the first release candidate on February 13th.

  7. #7
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    FixedLengthLineAggregator has padding and alignment. It isn't as fully featured as the String formatter option in 2.0, but it does pad numbers with spaces. Didn't it work in your case? You can probably write your own LineAggregator quite easily as well with String.format().

  8. #8
    Join Date
    Dec 2008
    Location
    Nashville, TN, USA
    Posts
    9

    Smile

    Thanks for your help. As I suspected, our team leader doesn't want to upgrade right now because too many code changes would be required and we're on a fairly tight deadline.

Posting Permissions

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