Java Utililty Methods Double Number Readable Format

List of utility methods to do Double Number Readable Format

Description

The list of methods to do Double Number Readable Format are organized into topic(s).

Method

StringhumanBytes(double bytes)
humanBytes formats bytes as a human readable string.
int base = 1024;
String[] pre = new String[] { "k", "m", "g", "t", "p", "e" };
String post = "b";
if (bytes < (long) base) {
    return String.format("%.2f b", bytes);
int exp = (int) (Math.log(bytes) / Math.log(base));
int index = exp - 1;
...
StringhumanBytes(double value)
human Bytes
String suffix = " B";
if (value > 1024) {
    value /= 1024;
    suffix = " KB";
if (value > 1024) {
    value /= 1024;
    suffix = " MB";
...
StringhumanReadableNumber(double n)
human Readable Number
if (n >= 1e9) {
    return String.format("%d billion", (Math.round(n / 1e9)));
} else if (n >= 1e6) {
    return String.format("%d million", (Math.round(n / 1e6)));
} else if (n >= 1e3) {
    return String.format("%d thousand", (Math.round(n / 1e3)));
} else if (n >= 1) {
    return String.format("%d", (Math.round(n)));
...
StringhumanReadableUnits(double bytes, boolean internationalSystemOfUnits)
human Readable Units
int unit = internationalSystemOfUnits ? 1000 : 1024;
if (bytes <= 0) {
    return ""; 
} else if (bytes < unit) {
    return "B";
int exp = (int) (Math.log(bytes) / Math.log(unit));
String pre = (internationalSystemOfUnits ? "kMGTPEZY" : "KMGTPEZY").charAt(exp - 1) + "";
...
StringhumanSize(double size)
human Size
if (size >= (1L << 40))
    return String.format("%.1fT", size / (1L << 40));
if (size >= (1L << 30))
    return String.format("%.1fG", size / (1L << 30));
if (size >= (1L << 20))
    return String.format("%.1fM", size / (1L << 20));
if (size >= (1L << 10))
    return String.format("%.1fK", size / (1L << 10));
...
StringtoMB(double inB)
to MB
if (inB < 0)
    return "-";
return String.format("%.0f", inB / (1024 * 1024));
doubletoMB(double n)
to MB
return toKB(n) / 1024;