List of utility methods to do Long Number Readable Format
String | getTrafficString(long bytes) get Traffic String if (bytes < KILO) return bytes + " bytes"; if (bytes < MEGA) return DECIMAL_FORMAT.format((double) bytes / KILO) + " kilobytes"; if (bytes < GIGA) return DECIMAL_FORMAT.format((double) bytes / MEGA) + " megabytes"; if (bytes < TERA) return DECIMAL_FORMAT.format((double) bytes / GIGA) + " gigabytes"; ... |
String | humanize(long value) humanize if (value < 0) return '-' + humanize(-value); else if (value > 1000000000000000000L) return Double.toString( (value + 500000000000000L) / 1000000000000000L * 1000000000000000L / 1000000000000000000.0) + 'E'; else if (value > 100000000000000000L) return Double.toString( ... |
String | humanizeBytes(long bytes) humanize Bytes int unit = 1000; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), "kMGTPE".charAt(exp - 1)); |
String | humanNumber(long num) human Number StringBuilder msg = new StringBuilder(); if (num >= 0) { int mag = 0; while (num >= 1000) { num = num / 10; mag++; char[] oMag = { 'K', 'M', 'G' }; ... |
String | humanreadable(long bytes, boolean si) humanreadable int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); |
String | humanReadable(long memory) Creates a human readable version of a memory amount if (memory < KB) return memory + " B"; int exp = (int) (Math.log(memory) / Math.log(KB)); String pre = "KMGTPE".charAt(exp - 1) + "i"; return String.format("%.1f %sB", memory / Math.pow(KB, exp), pre); |
String | humanReadable(long number) human Readable long absNumber = Math.abs(number); double result = number; String suffix = ""; if (absNumber < 1024L) { return String.valueOf(number); if (absNumber < 1048576L) { result = number / 1024.0D; ... |
String | humanReadableByteCount(final long bytes) human Readable Byte Count return humanReadableByteCount(bytes, true);
|
String | humanReadableByteCount(final long bytes, final boolean si) formats the bytes to a human readable format final int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; double result = bytes; final String unitsToUse = (si ? "k" : "K") + "MGTPE"; int i = 0; final int unitsCount = unitsToUse.length(); while (true) { ... |
String | humanReadableByteCount(long bytes) human Readable Byte Count int unit = 1024; if (bytes < unit) return bytes + "B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); char pre = "KMGTPE".charAt(exp - 1); return String.format("%.1f%s", bytes / Math.pow(unit, exp), pre); |