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;

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

        double k = (double) value / 1024;
        if (k == 0) {
            return String.format("%dB", value);
        }/*from  w ww  .  java2 s  .  c o m*/

        double m = k / 1024;
        if (m < 1) {
            return String.format("%.1fK", k);
        }

        double g = m / 1024;
        if (g < 1) {
            return String.format("%.1fM", m);
        }

        return String.format("%.1fG", g);
    }
}

Related

  1. toZeroPaddedString(long value, int precision, int maxSize)
  2. splitLongs(String str)
  3. convert2Percent(long readsize, long totalsize)
  4. formatSpaceSize(long file_size)
  5. formatPercent(long divisor, long dividend)
  6. formatSize(long value)
  7. getTimeFormattedFromMillis(long millis)