List of utility methods to do Long Readable Format
String | byteCountToDisplaySize(long size) byte Count To Display Size String displaySize; if (size / ONE_GB > 0) { displaySize = String.format("%1$.1f GB", (float) size / ONE_GB); } else if (size / ONE_MB > 0) { displaySize = String.format("%1$.1f MB", (float) size / ONE_MB); } else if (size / ONE_KB > 0) { displaySize = String.format("%1$.1f KB", (float) size / ONE_KB); } else { ... |
String | humanReadableByteCount(long bytes) human Readable Byte Count if (bytes < UNIT) { return bytes + "B"; int exp = (int) (Math.log(bytes) / Math.log(UNIT)); String pre = String.valueOf("KMGTPE".charAt(exp - 1)); return String.format(Locale.US, "%.1f%sB", bytes / Math.pow(UNIT, exp), pre); |
String | humanReadableByteCount(long bytes, boolean size) human Readable Byte Count int unit = size ? 1000 : 1024; if (bytes < unit) { return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (size ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (size ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); ... |
String | sizeConvert(long size) size Convert if (size <= 1024) { return "1Kb"; } else if (size > 1024 && size < 1024 * 1024) { return size / 1024 + "Kb"; } else { return size / 1024 / 1024 + "M"; |
String | prettyBytes(long value) pretty Bytes String args[] = { "B", "KB", "MB", "GB", "TB" }; StringBuilder sb = new StringBuilder(); int i; if (value < 1024L) { sb.append(String.valueOf(value)); i = 0; } else if (value < 1048576L) { sb.append(String.format("%.1f", value / 1024.0)); ... |
String | getSizeDesc(long size) get Size Desc String suffix = "B"; if (size >= 1024) { suffix = "K"; size = size >> 10; if (size >= 1024) { suffix = "M"; size = size >> 10; if (size >= 1024) { ... |
String | humanReadableByteCount(long bytes, boolean si) human Readable Byte Count int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = ("KMGTPE").charAt(exp - 1) + ""; return String.format(Locale.US, "%.1f %sB", bytes / Math.pow(unit, exp), pre); |
String | ReadableByteCount(long bytes) Readable Byte Count if (bytes < 1024) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(1024)); String pre = String.valueOf("KMGTPE".charAt(exp - 1)); return String.format("%.1f %sB", bytes / Math.pow(1024, exp), pre); |