hi all, i don't know..whether this is the right forum tp post this doubt.. First of all my doubt is,how to find the difference between 2 time values in java. i have 2 values time1= "9.20" time2="18.00" what i want is the difference 8.40.how to get it? also the second doubt how to round a fraction to 2 decimal points... 8.6667899 to 8.67. pls help thanx in advance
"meera", Thank you for changing your display name, but it still not correct.
We require display names to be two words: your first name, a space, then your last name. Fictitious names are not allowed.
Thanks, Dave [ October 10, 2005: Message edited by: David O'Meara ]
Sri Ram
Ranch Hand
Joined: Oct 03, 2005
Posts: 118
posted
0
------------------------------------------------------------- the second doubt how to round a fraction to 2 decimal points... 8.6667899 to 8.67. -------------------------------------------------------------
U can use NumberFormat Class. check the API for the method, i think its setMaximumFractionDigit(2). check the api for the method explanation.
---------------------------------------------------- the difference between 2 time values in java ----------------------------------------------------
U can convert the time to milliseconds, find the difference as its a integer and then convert back to hours.
Napa Sreedhar
Ranch Hand
Joined: Jan 29, 2002
Posts: 58
posted
0
1. Construct two GregorianCalendar objects gc1 and gc2 2. Calculate Elapsed Seconds long getElapsedSeconds(gc1, gc2) { Date d1 = gc1.getTime(); Date d2 = gc2.getTime(); long l1 = d1.getTime(); long l2 = d2.getTime(); long difference = Math.abs(l2 - l1); return difference / 1000; } 3. long seconds = getElapsedSeconds(gc1, gc2) int hours = (int)seconds / 3600; seconds = seconds - (hours * 3600); int minutes = (int) seconds / 60; int ss = (int)seconds - (minutes * 60);
Pratik Lohia
Ranch Hand
Joined: May 05, 2005
Posts: 88
posted
0
Use this ro round up to tow decimals.
public static double roundDoubleValue(double val2Round) { /* * Method to round off a recurring double value to a two decimal precision. * */ BigDecimal bd = new BigDecimal(val2Round); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); // now to remove zero after decimal return bd.doubleValue(); } // end of method roundDoubleValue
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.