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

java string align right

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:

enter image description here


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -