List of utility methods to do Long Number Readable Format
String | toHumanReadableSize(long bytes) to Human Readable Size boolean si = false; 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) + ""; return String.format("%.2f %sB", bytes / Math.pow(unit, exp), pre); |
String | toHumanSize(long bytes) to Human Size int unit = 0; double value = bytes; while (value > 4096) { value = value / 1024; unit++; if (unit == 0) { return String.valueOf(bytes) + units[unit]; ... |
String | toKilobytes(long bytes) This static method converts the passed in number of bytes into a kilobyte string grouping digits with locale-dependant thousand separator and with "KB" locale-dependant unit at the end. if (bytes < 0) return "? " + GENERAL_UNIT_KILOBYTES; long kbytes = bytes / 1024; if ((bytes & 512) != 0 || (bytes > 0 && bytes < 1024)) kbytes++; return NUMBER_FORMAT0.format(kbytes) + GENERAL_UNIT_KILOBYTES; |
String | toLocalizedInteger(long value) This static method converts the passed in number into a localizable representation of an integer, with digit grouping using locale dependant separators. return NUMBER_FORMAT0.format(value);
|
long | toMB(long b) to MB return b / (1024 * 1024);
|
String | toMB(long bytes) to MB if (bytes < 0) { return "n/a"; if (bytes > 1024 * 1024 * 1024) { return "" + (bytes / 1024 / 1024 / 1024) + "G"; } else if (bytes > 1024 * 1024) { return "" + (bytes / 1024 / 1024) + "M"; } else if (bytes > 1024) { ... |
String | toReadableBytes(long bytes) to Readable Bytes DecimalFormat df = new DecimalFormat("###,###.#"); if (bytes < 1024) { return df.format(bytes) + " bytes"; } else if (bytes < 1024 * 1024) { return df.format((float) bytes / 1024) + " KB"; } else if (bytes < 1024 * 1024 * 1024) { return df.format((float) bytes / 1024 / 1024) + " MB"; } else { ... |
String | toReadableNumber(long number) to Readable Number DecimalFormat df = new DecimalFormat("###,###"); return df.format(number); |
String | toStringLong(long id) to String Long long time = (System.currentTimeMillis() >> 42 << 42) + (id >> 22); long inc = (id >> 8) & xFFFFFF; long instanceId = id & xFF; return id + " (DEC)" + "\n" + toString(id) + " (HEX)" + "\ntime=" + SDF_MED.format(new Date(time)) + ", instanceId=" + instanceId + ", inc=" + inc; |