Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Beginning Java
Help with alignment
Donatas Latauskas
,
Greenhorn
Sep 18, 2006 13:13:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
I want to align by 'days' and 'needsToPay'. Please help me to find the right way how to do this.
while (register != null) { PeopleInfo reg = register.info; long from = reg.whenCameIn().getTime(); long to = reg.whenCameOut().getTime(); double difference = to - from; Date cameInDate = reg.whenCameIn(); DateFormat output = DateFormat.getDateInstance(DateFormat.MEDIUM); long days = Math.round((difference/(1000*60*60*24))); double needsToPay = days * reg.getDayCost(); if(lastName.equals("all") || lastName.trim().equals(reg.getLastName().trim())) { String forwriting; if(lastName.equals("all")) { forwriting = reg.getLastName() + "\t\t" + reg.getFirstName() + "\t" + output.format(cameInDate) + "\t" + days + "\t\t\t" + needsToPay; } else { forwriting = reg.getFirstName() + "\t" + output.format(cameInDate) + "\t" + days + "\t\t\t" + needsToPay; } rs.println(forwriting); } register = register.next; } if(rs != null) { rs.close(); }
Michael Dunn
,
Ranch Hand
Sep 18, 2006 15:37:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
one of the ways is to 'pad' the values for display
simplified example with hard-codes values
class Testing { public static void main(String[] args)//swap numbers { String[] days = {"1","10","100"}; double[] needsToPay = {1.01,10.01,100.01}; for(int x = 0; x < days.length; x++) { System.out.println(days[x]+"\t"+needsToPay[x]); } System.out.println("==="); String pad = " ";//adjust # of spaces to suit for(int x = 0; x < days.length; x++) { String temp1 = (pad+days[x]).substring(days[x].length()); String temp2 = (pad+needsToPay[x]).substring((""+needsToPay[x]).length()); System.out.println(temp1+"\t"+temp2); } } }
Donatas Latauskas
,
Greenhorn
Sep 19, 2006 14:35:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Thanks
Post by:
autobot
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
This thread has been viewed 458 times.
Similar Threads
Date Calculations - Difference between 2 dates is off
Java Calendar Daylight saving / Standard time
Using Sun's Migration Tool...
SimpleDateFormat (calculation)
I have a problem (help need in SQL and ResultSet)
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:47:31
.