Java Utililty Methods Byte Value Format

List of utility methods to do Byte Value Format

Description

The list of methods to do Byte Value Format are organized into topic(s).

Method

longbytesToMegabytes(long bytes)
bytes To Megabytes
return bytes / MEGABYTE;
StringbyteToHuman(long bytes, boolean si)
byte To Human
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);
StringbyteToHumanreadable(long b)
byte To Humanreadable
return (b / 1048576) + " MB";
intbyteToMeg(long bytes)
Converts bytes to megabytes.
return (int) (bytes / MB);