Java Size getDataSize(long size)

Here you can find the source of getDataSize(long size)

Description

get Data Size

License

Apache License

Declaration

public static String getDataSize(long size) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    private static DecimalFormat formater = new DecimalFormat("#,##0.00");

    public static String getDataSize(long size) {
        if (size < 1024) {
            return size + "bytes";
        } else if (size < 1024L * 1024) {
            double kbsize = size / 1024D;
            return formater.format(kbsize) + "KB";
        } else if (size < 1024L * 1024L * 1024) {
            double mbsize = size / 1024D / 1024D;
            return formater.format(mbsize) + "MB";
        } else if (size < 1024L * 1024L * 1024L * 1024) {
            double gbsize = size / 1024D / 1024D / 1024D;
            return formater.format(gbsize) + "GB";
        } else {/*from   w w w  . j a  va 2  s  . co  m*/
            double tbsize = size / 1024D / 1024D / 1024D / 1024D;
            return formater.format(tbsize) + "TB";
        }
    }
}

Related

  1. bytesToUnits(long size)
  2. calcSize(double s, String type, int div)
  3. createSizeFormat(Locale locale)
  4. getBytesSpecificationDescription(double sizeInBytes, String formatSpec)
  5. getByteStr(long size)
  6. getFontSizeInPoints(String fontSizeWithUnit)
  7. getFormatSize(double size)
  8. getFormatSize(long size)
  9. getFormattedSize(long size)