Android Long Format formatSize(long value)

Here you can find the source of formatSize(long value)

Description

format Size

Declaration

public static String formatSize(long value) 

Method Source Code

//package com.java2s;

import java.util.Locale;

public class Main {
    public static String formatSize(long value) {

        double k = (double) value / 1024;
        if (k == 0) {
            return String.format(Locale.CHINA, "%d B", value);
        }/* ww w  .  j  a  v a 2 s  .  c  o m*/

        double m = k / 1024;
        if (m < 1) {
            return String.format(Locale.CHINA, "%.2f K", k);
        }

        double g = m / 1024;
        if (g < 1) {
            return String.format(Locale.CHINA, "%.2f M", m);
        }

        return String.format(Locale.CHINA, "%.2f G", g);
    }
}

Related

  1. splitLongs(String str)
  2. convert2Percent(long readsize, long totalsize)
  3. formatSize(long value)
  4. formatSpaceSize(long file_size)
  5. formatPercent(long divisor, long dividend)
  6. getTimeFormattedFromMillis(long millis)
  7. formatFileSize(long length)
  8. ReadableByteCount(long bytes)
  9. getDisplayable(long numBytes)