This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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!
Consider Paul's rocket mass heater.
subject: Report Formatting