Java Size Format formatSize(long size)

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

Description

format Size

License

Open Source License

Declaration

public static String formatSize(long size) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {
    public static String formatSize(long size) {
        if (size > 1000000000)
            return DecimalFormat.getNumberInstance().format(size / 1000000000) + " GB";
        if (size > 1000000)
            return DecimalFormat.getNumberInstance().format(size / 1000000) + " MB";
        if (size > 1000)
            return DecimalFormat.getNumberInstance().format(size / 1000) + " KB";
        return DecimalFormat.getNumberInstance().format(size) + " B";
    }/*  w  ww .  j ava 2 s . c o  m*/
}

Related

  1. formatSize(long fileSize)
  2. formatSize(long longSize)
  3. formatSize(long longSize, int decimalPos)
  4. formatSize(long size)
  5. formatSize(long size)
  6. formatSize(long size)
  7. formatSize(long size)
  8. formatSize(long size, boolean forceFixLen, boolean forceSizeInBytes)
  9. formatSize(long sizeInByte)