java - NumberFormat for report formatting -
i'm trying quick report in java , i'm having issues formatting numbers. here's have now:
messageformat lineformat = new messageformat("{0}\t{1,number,#,##0}\t    {2,number,#0}\t\t {3,number,#0.00}"); the problem array index 1 (and 3 some) hundreds , thousands , setting eliminates positions, have on output:
feb 16, 2015    414     42       9.86 feb 17, 2015    1,908   81       23.56 feb 19, 2015    786     43       18.28 feb 20, 2015    1,331   99       13.44 i want index 1 , index 3 parameters align on right instead of left report looks neat.
i have read decimalformat , numberformat java docs , googled , can't seem find solution.
when want format strings far alignment, using string.format() sufficient enough alignment.
references:
http://www.homeandlearn.co.uk/java/java_formatted_strings.html
public static void main(string[] args) throws exception {     // prints number, 10 characters right justified     system.out.println(string.format("%10d", 123456));      // prints number, 10 characters left justified     system.out.println(string.format("%-10d", 123456));      system.out.println(string.format("%10s", "12345"));     system.out.println(string.format("%-10s", "12345"));      // still prints characters, since exceeds expected 10 characters it's printed     system.out.println(string.format("%10s", "123456789101112")); } results:

Comments
Post a Comment