public static function formatMemory($bytes, $precision = 3)
    {
        $absBytes = abs($bytes);
        $sign = ($bytes == $absBytes) ? 1 : -1;
        $suffix = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
        $total = count($suffix);

        for ($i = 0; $absBytes > 1024 && $i < $total; $i++) {
            $absBytes /= 1024;
        }

        return self::toPrecision($sign * $absBytes, $precision) . $suffix[$i];
    }
public static function formatMemory($bytes, $precision = 3)
    {
        $absBytes = abs($bytes);
        $sign = ($bytes == $absBytes) ? 1 : -1;
        $suffix = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
        $total = count($suffix);

        for ($i = 0; $absBytes > 1024 && $i < $total; $i++) {
            $absBytes /= 1024;
        }

        return self::toPrecision($sign * $absBytes, $precision) . $suffix[$i];
    }
public static function formatMemory ( $ bytes , $ precision = 3 ) { $ absBytes = abs ( $ bytes ) ; $ sign = ( $ bytes == $ absBytes ) ? 1 : - 1 ; $ suffix = [ 'B' , 'kB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ; $ total = count ( $ suffix ) ; for ( $ i = 0 ; $ absBytes > 1024 && $ i < $ total ; $ i ++ ) { $ absBytes /= 1024 ; } return self :: toPrecision ( $ sign * $ absBytes , $ precision ) . $ suffix [ $ i ] ; }
Format a byte count into a human-readable representation.

@param integer $bytes     Byte count to convert. Can be negative.
@param integer $precision How many decimals to include.

@return string
Format a byte count into a human - readable representation .