function bytes2human ($bytes, $precision
{
switch (true) {
case $bytes < 1024:
return number_format$bytes).($bytes==1 ? " Byte" : " Bytes");
case round$bytes / 1024) < 1024:
return number_format$bytes / 1024, $precision)." KB"
case round$bytes / 1024 / 1024, 2) < 1024:
return number_format$bytes / 1024 / 1024, $precision)." MB"
case round$bytes / 1024 / 1024 / 1024, 2) < 1024:
return number_format$bytes / 1024 / 1024 / 1024, $precision)." GB"
default
return number_format$bytes / 1024 / 1024 / 1024 / 1024, $precision)." TB"
}
}
eXorithm – Execute Algorithm: View / Run Algorithm bytes2human
