Android Long Format formatFromSize(long size)

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

Description

format From Size

Declaration

public static String formatFromSize(long size) 

Method Source Code

//package com.java2s;

public class Main {

    public static String formatFromSize(long size) {
        if (size == -1)
            return "";
        String suffix = " B";
        if (size >= 1024) {
            suffix = " KB";
            size /= 1024;// w w  w. j  a  v a2s.  c om
            if (size >= 1024) {
                suffix = " MB";
                size /= 1024;
            }
        }

        StringBuilder resultBuffer = new StringBuilder(Long.toString(size));

        int commaOffset = resultBuffer.length() - 3;
        while (commaOffset > 0) {
            resultBuffer.insert(commaOffset, ',');
            commaOffset -= 3;
        }

        if (suffix != null)
            resultBuffer.append(suffix);
        return resultBuffer.toString();
    }
}

Related

  1. getTimeFormattedFromMillis(long millis)
  2. formatFileSize(long length)
  3. ReadableByteCount(long bytes)
  4. getDisplayable(long numBytes)
  5. formatByte(long l)