Friday, July 31, 2020

JAVA Code to convert Bytes into MB

Here is the JAVA Code to convert bytes in MB upto 1 decimal place.

public void getSizeInMB()
    {
        long sizeinBytes = 200*1024;
                long sizeInKB = sizeinBytes/1024;
                long sizeInMBInt = sizeInKB/1024;
                float sizeInMB = sizeInKB/1024.0f;
                String size = sizeInMB+"";

                int k = size.indexOf('.');
                size = sizeInMBInt+"."+size.charAt(k+1);
   
      System.out.print(size);
    }

No comments:

Post a Comment