List of utility methods to do Long Number Readable Format
String | humanReadableNumber(long total) human Readable Number DecimalFormat formatter = (DecimalFormat) NumberFormat.getInstance(Locale.US);
return formatter.format(total);
|
String | humanReadableSize(long byteCount) Returns a human-readable (memory, file, ...) size. String result; if (byteCount / GB_BYTES > 0) { result = Long.toString(byteCount / GB_BYTES) + " GB"; } else if (byteCount / MB_BYTES > 0) { result = Long.toString(byteCount / MB_BYTES) + " MB"; } else if (byteCount / KB_BYTES > 0) { result = Long.toString(byteCount / KB_BYTES) + " kB"; } else { ... |
String | humanReadableSize(long bytes) Human readable size conversion. Credit: 'aioobe' at 'StackOverFlow.com' int unit = 1024; if (bytes < unit) { return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = ("KMGTPE").charAt(exp - 1) + ("i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); |
String | humanReadableTime(final long duration) human Readable Time String unit = ""; long mins = duration / (60L * 1000); long hr = mins / 60; long yrs = hr / 24 / 365; if (mins <= 0) { long secs = duration / 1000; unit = secs + " sec"; if (secs > 1) { ... |
String | humanTimeDiff(long timeDiff) human Time Diff if (timeDiff < 1000) { return String.format("%dmsec", timeDiff); StringBuilder buf = new StringBuilder(); long hours = timeDiff / (60 * 60 * 1000); long rem = (timeDiff % (60 * 60 * 1000)); long minutes = rem / (60 * 1000); rem = rem % (60 * 1000); ... |
String | readable(long bytes) readable DecimalFormat df = new DecimalFormat("#.###"); if (bytes >= GB) { return df.format((double) bytes / GB) + "GB"; } else if (bytes >= MB) { return df.format((double) bytes / MB) + "MB"; } else if (bytes >= KB) { return df.format((double) bytes / KB) + "KB"; } else { ... |
String | stringForBytes(long bytes) Return a human-readable indication of a size, given a number of bytes. DecimalFormat deci = new DecimalFormat("0.00"); double gigs = (((double) bytes / 1024d) / 1024d / 1024d); double megs = (((double) bytes / 1024d) / 1024d); double kb = ((double) bytes / 1024d); if (gigs > 1) { return deci.format(gigs) + " GB"; if (megs > 1) { ... |
String | stringify(long byteNumber) Formatter byte to kb,mb or gb etc. if (byteNumber / TB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) TB_IN_BYTES) + "TB"; } else if (byteNumber / GB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) GB_IN_BYTES) + "GB"; } else if (byteNumber / MB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) MB_IN_BYTES) + "MB"; } else if (byteNumber / KB_IN_BYTES > 0) { return df.format((double) byteNumber / (double) KB_IN_BYTES) + "KB"; ... |
String | toHuman(long amount) to Human return humanReadableByteCount(amount, true);
|
String | toHumanReadableSize(long byteCount) to Human Readable Size if (byteCount >= 10 * 1024 * 1024) { return (byteCount / (1024 * 1024)) + "MB"; } else if (byteCount >= 10 * 1024) { return (byteCount / 1024) + "kB"; } else { return Long.toString(byteCount); |