Networking\InitCmsBundle\Twig\Extension\NetworkingHelperExtension::getHumanReadableSize PHP Метод

getHumanReadableSize() публичный Метод

public getHumanReadableSize ( $size, null $unit = null, integer $decemals = 2 ) : string
$size
$unit null
$decemals integer
Результат string
    public function getHumanReadableSize($size, $unit = null, $decemals = 2)
    {
        $byteUnits = array(' B', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB');
        if (!is_null($unit) && !in_array($unit, $byteUnits)) {
            $unit = null;
        }
        $extent = 1;
        foreach ($byteUnits as $rank) {
            if (is_null($unit) && $size < ($extent <<= 10) || $rank == $unit) {
                break;
            }
        }
        return number_format($size / ($extent >> 10), $decemals) . $rank;
    }