Hi people Hope maybe someone could figure this one out. I am trying to write some code that displays the time in seconds to millisecond precision i.e. 1.354. Unfortnatley my code at the moment displays 1.354 seconds as 1354. Could someone let me know how to cast this correctly i have included my code below. public long dt = 0; public long startTime = System.currentTimeMillis(); dt = System.currentTimeMillis() - startTime; print(dt); thanks for your time
The time difference you measure will be in milliseconds; hence the name "currentTimeMillis()". If you want the time in seconds, then divide by 1000: print(dt/1000.0);
John, In order to have the print only show three values after the decimal use a DecimalFormat object: DecimalFormat df = new DecimalFormat( "#0.000" ); System.out.println(df.format(value));