src/MemoryUtil.php
public static function convertSize( int $value, int $unit, int $precision = self::DEFAULT_PRECISION ) : float
    {
        switch ( $unit ){
        case EnumMemoryUnit::UNIT_B:
            return (float)$value;
        case EnumMemoryUnit::UNIT_KB:
            return round( ((float)$value) / self::BYTES_KB, $precision );
        case EnumMemoryUnit::UNIT_MB:
            return round( ((float)$value) / self::BYTES_MB, $precision );
        case EnumMemoryUnit::UNIT_GB:
            return round( ((float)$value) / self::BYTES_GB, $precision );
        case EnumMemoryUnit::UNIT_TB:
            return round( ((float)$value) / self::BYTES_TB, $precision );
        }
        return (float)$value;
    }
public static function convertSize( int $value, int $unit, int $precision = self::DEFAULT_PRECISION ) : float
    {
        switch ( $unit ){
        case EnumMemoryUnit::UNIT_B:
            return (float)$value;
        case EnumMemoryUnit::UNIT_KB:
            return round( ((float)$value) / self::BYTES_KB, $precision );
        case EnumMemoryUnit::UNIT_MB:
            return round( ((float)$value) / self::BYTES_MB, $precision );
        case EnumMemoryUnit::UNIT_GB:
            return round( ((float)$value) / self::BYTES_GB, $precision );
        case EnumMemoryUnit::UNIT_TB:
            return round( ((float)$value) / self::BYTES_TB, $precision );
        }
        return (float)$value;
    }
public static function convertSize ( int $ value , int $ unit , int $ precision = self :: DEFAULT_PRECISION ) : float { switch ( $ unit ) { case EnumMemoryUnit :: UNIT_B : return ( float ) $ value ; case EnumMemoryUnit :: UNIT_KB : return round ( ( ( float ) $ value ) / self :: BYTES_KB , $ precision ) ; case EnumMemoryUnit :: UNIT_MB : return round ( ( ( float ) $ value ) / self :: BYTES_MB , $ precision ) ; case EnumMemoryUnit :: UNIT_GB : return round ( ( ( float ) $ value ) / self :: BYTES_GB , $ precision ) ; case EnumMemoryUnit :: UNIT_TB : return round ( ( ( float ) $ value ) / self :: BYTES_TB , $ precision ) ; } return ( float ) $ value ; }
convert memory size

@param int $value           memory size in bytes to be converted
@param int $unit            memory unit to be converted
@param int $precision       precision

@return float     converted size
convert memory size