Public feed #923984

Macca

public text v1 · immutable
Raw Edit
·published 2008-03-01 00:13 UTC
rendered paste body
    public static string FormatFileSize(long Size)
    {
        string[] Suffixes = new string[] { "B", "KB", "MB", "GB", "TB" };
        int SuffixIndex = 0;
        double WorkingSize = (double)Size;

        while (WorkingSize > 0 && SuffixIndex < Suffixes.Length)
        {
            WorkingSize /= 1024;
        }

        if (WorkingSize < 0 && SuffixIndex > 0)
        {
            WorkingSize *= 1024;
            SuffixIndex--;
        }

        return string.Format("{0:0.00} {1}", WorkingSize, Suffixes[SuffixIndex]);
    }