public static function formatSize($size, $unit = null, $decimals = 2) {


        // Initialize the units.
        $units = static::getUnits();

        // Find the unit.
        $index = array_search($unit, $units);
        if (null !== $unit && false === $index) {
            throw new IllegalArgumentException("The unit \"" . $unit . "\" does not exists");
        }

        // Initialize the output.
        $output = $size;

        $iteration = 0;
        while (self::FILE_SIZE_DIVIDER <= $output || $iteration < $index) {
            $output /= self::FILE_SIZE_DIVIDER;
            ++$iteration;
        }

        // Return the output.
        return implode(" ", [sprintf("%." . $decimals . "f", $output), $units[$iteration]]);
    }
public static function formatSize($size, $unit = null, $decimals = 2) {


        // Initialize the units.
        $units = static::getUnits();

        // Find the unit.
        $index = array_search($unit, $units);
        if (null !== $unit && false === $index) {
            throw new IllegalArgumentException("The unit \"" . $unit . "\" does not exists");
        }

        // Initialize the output.
        $output = $size;

        $iteration = 0;
        while (self::FILE_SIZE_DIVIDER <= $output || $iteration < $index) {
            $output /= self::FILE_SIZE_DIVIDER;
            ++$iteration;
        }

        // Return the output.
        return implode(" ", [sprintf("%." . $decimals . "f", $output), $units[$iteration]]);
    }
public static function formatSize ( $ size , $ unit = null , $ decimals = 2 ) { // Initialize the units. $ units = static :: getUnits ( ) ; // Find the unit. $ index = array_search ( $ unit , $ units ) ; if ( null !== $ unit && false === $ index ) { throw new IllegalArgumentException ( "The unit \"" . $ unit . "\" does not exists" ) ; } // Initialize the output. $ output = $ size ; $ iteration = 0 ; while ( self :: FILE_SIZE_DIVIDER <= $ output || $ iteration < $ index ) { $ output /= self :: FILE_SIZE_DIVIDER ; ++ $ iteration ; } // Return the output. return implode ( " " , [ sprintf ( "%." . $ decimals . "f" , $ output ) , $ units [ $ iteration ] ] ) ; }
Format a size.

@param  $size The size.
@param string $unit The unit.
@return string Returns the formated size.
Format a size .