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 :)