27

I have an array of these numbers

61672
8414449
264957

I use a DecimalFormat object like this

DecimalFormat formatter = new DecimalFormat("###,### bytes");

to get these results

61,672 bytes
8,414,449 bytes
264,957 bytes

but I need the results to be aligned to right like the following

   61,672 bytes
8,414,449 bytes
  264,957 bytes

Your help is already appreciated.

David Weng
  • 3,985
  • 12
  • 38
  • 49

1 Answers1

46

You can wrap it into a String.format call like this:

String.format("%15s", formatter.format(i))
Howard
  • 36,183
  • 6
  • 60
  • 81