Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Padding for DecimalFormat?

Reply
Thread Tools

Padding for DecimalFormat?

 
 
Timo Nentwig
Guest
Posts: n/a
 
      01-05-2004
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
 
Reply With Quote
 
 
 
 
Thomas Schodt
Guest
Posts: n/a
 
      01-05-2004
Timo Nentwig wrote:

> 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;
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      01-05-2004
On Mon, 05 Jan 2004 13:29:39 +0000, Thomas Schodt
<> wrote or quoted :

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

>
>Not without extra processing.


Java presumes you will display the result in a JTextField that lets
you specify right or left justification. It generally has no built in
features for padding with left zeroes. Misc.LZ will do it for you in
from http://mindprod.com/products.html#BUS

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Tony Dahlman
Guest
Posts: n/a
 
      02-12-2004
Timo Nentwig wrote:
>
> 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/Pr...dDecimalFormat

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

Regards, Tony Dahlman
---------------------------------------
Fax: USA 530 846-6802
(Sorry, email abused too much)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Padding is invalid and cannot be removed. pls help Robert Smith ASP .Net 0 12-08-2005 02:14 PM
VB code and Sql Server Ansi Padding =?Utf-8?B?U2FuZHk=?= ASP .Net 2 05-11-2005 07:16 PM
padding left-justified string fields Dave Perl 7 07-22-2004 09:55 AM
Padding between textboxes Becker ASP .Net 4 06-24-2004 04:00 PM
How to align table with some left padding? RA ASP .Net 1 02-19-2004 06:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57