Formatar tamanho de arquivos

<< Click to Display Table of Contents >>

Navigation:  Funções >

Formatar tamanho de arquivos

Previous pageReturn to chapter overviewNext page

       

       public static string GetSizeHumanRedable(long bytes)

       {

          string[] suf = {"bytes", "Kb", "Mb", "Gb", "Tb", "Pb"};

          int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));

          double num = Math.Round(bytes / Math.Pow(1024, place), 1);

          return num.ToString() + "<i>" + suf[place] + "</i>";

       }