I tried to find a solution for this, but I just can't. I want to show a megabyte long representation, which is calculated in bytes.
In Java, you got a length () method that you can call on a file object. It will return the size of the files in bytes stored in long. Now I want so long and turn it into megabytes, not bytes. The file I'm trying to get is 161,000 bytes in size. If I'm not mistaken, this translates to 0.161 megabytes. So I would make bytes / 100000, and I would expect to get 0.161. The problem is that I do not.
If I go to my Windows calculator or any other calculator, the application will be able to show these 3 decimal places. Why can't I do this? I tried storing the result in a double that just appears as 0.0
EDIT: Answers found. Thanks wrm:
long b = file.length (); double mb = (double) b / (1024 * 1024);
source share