• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DecimalFormat

 
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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??
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 Format.java 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.
reply
    Bookmark Topic Watch Topic
  • New Topic