long startTime = System.currentTimeMillis();
float resultTime= (System.currentTimeMillis() - startTime) / 1000;
System.out.println("Result time : " + resultTime);
The result is always a rounded value like 1.0 or 2.0.
How can I obtain an exact result like 1.234?
You’re doing integer division. (which rounds down to an integer)
Cast to
floatbefore you do the division: