CmisSync.Lib.Utils.FormatSize C# (CSharp) Method

FormatSize() public static method

Format a file size nicely. Example: 1048576 becomes "1 MB"
public static FormatSize ( double byteCount ) : string
byteCount double
return string
        public static string FormatSize(double byteCount)
        {
            if (byteCount >= 1099511627776)
                return String.Format("{0:##.##} TB", Math.Round(byteCount / 1099511627776, 1));
            else if (byteCount >= 1073741824)
                return String.Format("{0:##.##} GB", Math.Round(byteCount / 1073741824, 1));
            else if (byteCount >= 1048576)
                return String.Format("{0:##.##} MB", Math.Round(byteCount / 1048576, 0));
            else if (byteCount >= 1024)
                return String.Format("{0:##.##} KB", Math.Round(byteCount / 1024, 0));
            else
                return byteCount.ToString() + " bytes";
        }

Same methods

Utils::FormatSize ( long byteCount ) : string

Usage Example

Ejemplo n.º 1
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     this.stream.Write(buffer, offset, count);
     if (isDebuggingEnabled)
     {
         writepos += count;
         long percentage = (writepos * 100) / (Length > 0?Length:100);
         Logger.Debug(String.Format("{0}% {1} of {2})",
                                    percentage,
                                    Utils.FormatSize(this.writepos),
                                    Utils.FormatSize(Length)));
     }
 }
All Usage Examples Of CmisSync.Lib.Utils::FormatSize