I want to convert milliseconds to seconds (for example 1500ms to 1.5s, or 500ms to 0.5s) with as much precision as possible.
Double.parseDouble(500 / 1000 + "." + 500 % 1000);
isn't the best way to do it: I'm looking for a way to get the remainder from a division operation so I could simply add the remainder on.
This question is related to
java
precision
divide
milliseconds
I had this problem too, somehow my code did not present the exact values but rounded the number in seconds to 0.0 (if milliseconds was under 1 second). What helped me out is adding the decimal to the division value.
double time_seconds = time_milliseconds / 1000.0; // add the decimal
System.out.println(time_milliseconds); // Now this should give you the right value.
Why don't you simply try
System.out.println(1500/1000.0);
System.out.println(500/1000.0);
Source: Stackoverflow.com