Java Size size2human(long size)

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

Description

sizehuman

License

LGPL

Declaration

public static String size2human(long size) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.text.DecimalFormat;

public class Main {
    private static final long SIZE_GIGABYTE = 1024 * 1024 * 1024;
    private static final long SIZE_MEGABYTE = 1024 * 1024;
    private static final long SIZE_KILOBYTE = 1024;

    public static String size2human(long size) {
        if (size > SIZE_GIGABYTE) {
            DecimalFormat df = new DecimalFormat("#.00");
            return df.format(((size + SIZE_GIGABYTE / 2) / SIZE_GIGABYTE)) + " GB";
        }//from   w  w w  .j  a v a  2 s .  c o m
        if (size > SIZE_MEGABYTE) {
            return ((size + SIZE_MEGABYTE / 2) / SIZE_MEGABYTE) + " MB";
        }
        return ((size + SIZE_KILOBYTE / 2) / SIZE_KILOBYTE) + " KB";
    }
}

Related

  1. readableSize(long size)
  2. readableSize(long size)
  3. readableSize(long size, DecimalFormat format)
  4. renderNumber(int n, int size)
  5. size(long l)
  6. sizeRenderer(String value)
  7. stringToSize(String sizeString)
  8. toByte(String size)
  9. toHumanReadableSize(final long pSizeInBytes)