public static function formatBytes($iBytes, $iPrecision = 2)
    {
        $units  = ['B', 'KB', 'MB', 'GB', 'TB'];
        $iBytes = max($iBytes, 0);
        $pow    = floor(($iBytes ? log($iBytes) : 0) / log(1024));
        $pow    = min($pow, count($units) - 1);

        //  Uncomment one of the following alternatives
        //$iBytes /= pow(1024, $pow);
        $iBytes  /= (1 << (10 * $pow));
        $var     = round($iBytes, $iPrecision) . ' ' . $units[$pow];
        $pattern = '/(.+?)\.(.*?)/';

        return preg_replace_callback(
            $pattern,
            function ($matches) {
                return number_format($matches[1]) . '.' . $matches[2];
            },
            $var
        );
    }