Padding for DecimalFormat?

T

Timo Nentwig

Hi!

Is there no padding/alignment for DecimalFormat?

d = new DecimalFormat("00000000");
d.format(1234);

will return "00001234". "########" will return "1234". And how do I get "
1234"?

Timo
 
T

Thomas Schodt

Timo said:
Is there no padding/alignment for DecimalFormat?

d = new DecimalFormat("00000000");
d.format(1234);

will return "00001234". "########" will return "1234".
And how do I get " 1234"?

Not without extra processing.

NumberFormat d = new DecimalFormat("########");
String s = d.format(1234);
String s0 = " ".substring(s.length()) + s;
 
T

Tony Dahlman

Timo said:
Hi!

Is there no padding/alignment for DecimalFormat?

d = new DecimalFormat("00000000");
d.format(1234);

will return "00001234". "########" will return "1234". And how do I get "
1234"?

Timo

You got good answers. But I should add that a really simple way (if you're
not pasting the result into a JTextField) is:

http://pws.prserv.net/ad/programs/Programs.html#PaddedDecimalFormat

Oh, and please let me know if you improve on it.

Regards, Tony Dahlman
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top