The moose likes Beginning Java and the fly likes Report Formatting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Report Formatting" Watch "Report Formatting" New topic

Report Formatting

Mark Mokris
Ranch Hand

Joined: May 08, 2002
Posts: 61
I was wondering how you format a hard copy printout or report in Java. What classes do I look to? Suppose I want to format numbers as dollars and cents, right-justified within 15 print positions, like you can do in other languages.
Hari Gangadharan
Ranch Hand

Joined: Mar 08, 2001
Posts: 73
Seems like you are a COBOL programmer :-). I too was! It is very difficult to format text reports using Java comparing COBOL or older languages that can create reports. You can use the following classes to format the Date and Number: SimpleDateFormat and NumberFormat (Look in java.text package).
However there is no StringFormat class that enables us to right align or left align our strings during report generation. You may have to create your own StringFormat class that can append spaces in front or back - A sample use of the StringFormat may be as follows (Remember you have to create StringFormat):

Hope this helps.
[ February 05, 2003: Message edited by: Hari Gangadharan ]

<B>Hari Gangadharan</B><BR>Unix is user friendly..<BR>but it chooses to whom it is friendly with!
I agree. Here's the link:
subject: Report Formatting
It's not a secret anymore!