Java Size getFormatSize(double size)

Here you can find the source of getFormatSize(double size)

Description

get Format Size

License

Apache License

Declaration

private static String getFormatSize(double size) 

Method Source Code

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

import java.text.NumberFormat;

public class Main {
    public static final String[] FILE_SIZE_UNIT = { "Byte", "KB", "MB", "GB", "TB", "PB" };

    private static String getFormatSize(double size) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(2);// w  w w .  j  av  a 2s.  c  om
        int i = 0;
        String[] unit = FILE_SIZE_UNIT;
        for (i = 0; i < unit.length; i++) {
            if ((long) (size / 1024) > 0) {
                size /= 1024;
            } else {
                break;
            }
        }
        return nf.format(size) + unit[i];
    }
}

Related

  1. createSizeFormat(Locale locale)
  2. getBytesSpecificationDescription(double sizeInBytes, String formatSpec)
  3. getByteStr(long size)
  4. getDataSize(long size)
  5. getFontSizeInPoints(String fontSizeWithUnit)
  6. getFormatSize(long size)
  7. getFormattedSize(long size)
  8. getReadableByteSize(long size)
  9. getReadableSize(long size)