Android Long Format formatSpaceSize(long file_size)

Here you can find the source of formatSpaceSize(long file_size)

Description

format Space Size

Declaration

public static String formatSpaceSize(long file_size) 

Method Source Code

//package com.java2s;

import java.text.DecimalFormat;

public class Main {
    public final static DecimalFormat NO_DECIMAL_POINT_DF = new DecimalFormat(
            "0");
    public final static DecimalFormat ONE_DECIMAL_POINT_DF = new DecimalFormat(
            "0.0");

    public static String formatSpaceSize(long file_size) {
        if (file_size < 1024) { 
            return file_size + "B";
        } else if (file_size < 1024 * 1024) { 
            return NO_DECIMAL_POINT_DF.format((double) file_size / 1024)
                    + "KB";
        } else if (file_size < 1024 * 1024 * 1024) { 
            return NO_DECIMAL_POINT_DF
                    .format((double) file_size / 1024 / 1024) + "MB";
        } else {/*from   www.j av  a  2 s .  co m*/
            return ONE_DECIMAL_POINT_DF
                    .format((double) file_size / 1024 / 1024 / 1024) + "GB";
        }
    }
}

Related

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