Jyxo\StringUtil::formatBytes PHP Method

formatBytes() public static method

Converts given size in bytes to kB, MB, GB, TB or PB and appends the appropriate unit.
public static formatBytes ( float $size, string $decimalPoint = ',', string $thousandsSeparator = ' ' ) : string
$size float Input size
$decimalPoint string Decimal point
$thousandsSeparator string Thousands separator
return string
    public static function formatBytes(float $size, string $decimalPoint = ',', string $thousandsSeparator = ' ') : string
    {
        static $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
        foreach ($units as $unit) {
            if ($size < 1024) {
                break;
            }
            $size = $size / 1024;
        }
        $decimals = 'B' === $unit || 'kB' === $unit ? 0 : 1;
        return number_format($size, $decimals, $decimalPoint, $thousandsSeparator) . ' ' . $unit;
    }