The list of methods to do Byte Value Format are organized into topic(s).
String
bytesToHuman(long bytes) Converts a given number of bytes to a human readable format.
if (bytes < 1024) {
return bytes + " B";
int bitsUsed = 63 - Long.numberOfLeadingZeros(bytes);
double significand = (double) bytes / (1L << (bitsUsed - bitsUsed % 10));
char prefix = "kMGTPE".charAt(bitsUsed / 10 - 1);
return String.format("%.1f %sB", significand, prefix);
String
bytesToHuman(long size) bytes To Human
if (size < 1024L) {
return size + "bytes";
} else if (size < 1024L * 1024L) {
return String.format("%.2fkb", (double) size / 1024L);
} else if (size < 1024L * 1024L * 1024L) {
return String.format("%.2fmb", (double) size / (1024L * 1024L));
} else if (size < 1024L * 1024L * 1024L * 1024L) {
return String.format("%.2fgb", (double) size / (1024L * 1024L * 1024L));
...
String
bytesToHumanReadable(int bytes) bytes To Human Readable
float fbytes = (float) bytes;
String[] mags = new String[] { "", "k", "m", "g", "t" };
int magIndex = 0;
while (fbytes >= 1024) {
fbytes /= 1024;
magIndex++;
return String.format("%.2f%sb", fbytes, mags[magIndex]);
...
long
bytesToKBytes(long bytes) bytes To K Bytes
long kBytes = bytes / 1024;
long remainder = bytes % 1024;
if (remainder > 0)
kBytes += 1;
return kBytes;