Here you can find the source of size2human(long size)
public static String size2human(long size)
//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"; } }