Feb 3rd, 2009, 10:03 AM
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
Feb 3rd, 2009, 05:14 PM
What version of Spring Batch are you using? This was something we recognized and fixed in 2.0.
Feb 4th, 2009, 08:02 AM
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?
Feb 4th, 2009, 08:07 AM
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:
It's not an exhaustive list, but its a pretty reasonable summary.
Feb 4th, 2009, 08:46 AM
Looking at the Spring Batch download area, it appears 2.0 is not a GA release, yet. How stable is it?
Feb 4th, 2009, 10:40 AM
I would say it's pretty stable. We plan to release the first release candidate on February 13th.
Feb 4th, 2009, 02:34 PM
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().
Feb 5th, 2009, 08:25 AM
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.