Android examples for java.lang:long
format Size with if else ladder
public class Main { public static String formatSize(long size) { long l = size; String s = "GB"; if (l > 1024 * 1024 * 1024) { l /= 1024 * 1024 * 1024;// w w w . j av a2s .c o m } else if (l > 1024 * 1024) { l /= 1024 * 1024; s = "MB"; } else if (l > 1024) { l /= 1024; s = "KB"; } else { s = "B"; } return String.valueOf(l) + s; } }