Hi all,
I'm formatting some text output and want to format an int so that the resulting
String is:
* the resulting String is a minimum of (say) n characters wide
* the integer is right-aligned
* the string is padded out with spaces, not '0's.
Ie, I want format(int num, int spaces) such that:
format (100, 6) => ' 100'
format (10000), 6) => ' 10000'
I thought I'd be able to do this in two lines with DecimalFormat or NumberFormat, but I can't work it out. Am I missing something blindingly obvious?!
This is the sort of code I'm playing around with, it seems like I can either have space pads and left-alignment, or '0' pads and right-alignment.
I know it'd be trivial to write a function myself to do this, but I'm wondering if the standard
Java libraries make it possible...I was sure they would
Maybe I should rewrite in Perl?? ;-)
Cheers,
-Tim
BTW, the specification for
patterns in DecimalFormat is here:
http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html