Here you can find the source of convertByteUnit(Long l)
public static String convertByteUnit(Long l)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { /**//from w w w. j a v a 2 s. com * Converts a given number to byte units, i.e. KiloByte, MegaByte etc. */ public static String convertByteUnit(Long l) { String s = null; String[] unit = { "B", "KB", "MB", "GB", "TB" }; int i = 0; if (l < 1024) { s = "" + l; } else { float del = 1024.0f; float f = l; while (f > del) { // System.out.println(i + " " + f); i++; f /= del; } // System.out.println(i + " " + f); DecimalFormat df = new DecimalFormat("0.00"); s = df.format(f); } s += " " + unit[i]; return s; } }