Here you can find the source of formatByteSize(long byteSize)
public static String formatByteSize(long byteSize)
//package com.java2s; //License from project: Open Source License public class Main { public static String formatByteSize(long byteSize) { float size = (float) byteSize; String metrics = " b"; if (size >= 1024) { size = size / 1024;/*from w w w .j av a2 s .c om*/ metrics = " Kb"; } if (size >= 1024) { size = size / 1024; metrics = " Mb"; } String sizeStr = "" + size; int idx = sizeStr.indexOf("."); if (idx != -1) { if (sizeStr.charAt(idx + 1) != '0') { sizeStr = sizeStr.substring(0, idx + 2); } else { sizeStr = sizeStr.substring(0, idx); } } sizeStr += metrics; return sizeStr; } }