This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes DecimalFormat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "DecimalFormat" Watch "DecimalFormat" New topic


Gail Mikels
Ranch Hand

Joined: May 07, 2001
Posts: 634
I need to format currency in a JTextArea, and would like it to appear in a column (with the decimal points aligned).
I've tried decimal format ("####.00"), but I found that the "#" isn't actually a placeholder.
Any advice??

Gail Mikels
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
I don't think DecimalFormat can do what you want. Alternatives: (1) use format "0000.00" and put up with leading zeros, (2) put the values into some other GUI component which allows you to align them along the right side (I don't remember Swing well enough to tell you how to do this), (3) write your own method which will pad a string with spaces on the left hand side to bring it up to a specified length, ot (4) use Cay Horstman's to get a Java equivalent of C's printf statement. Note that all options but #2 assume you're using a fixed-width font - otherwise text alignment is pretty hopeless.

"I'm not back." - Bill Harding, Twister
jQuery in Action, 2nd edition
subject: DecimalFormat
Similar Threads
displaying decimal numbers
Rounding problem
Reg. Integer literals
HSSF and getNumericCellValue()
decimal format