- private static string ConvertUnit(long size)
- {
- string FileSize = string.Empty;
- if (size > (1024 * 1024 * 1024))
- FileSize = string.Format("{0}GB",((double)size / (1024 * 1024 * 1024)).ToString(".##"));
- else if (size > (1024 * 1024))
- FileSize = string.Format("{0}MB", ((double)size / (1024 * 1024)).ToString(".##"));
- else if (size > 1024)
- FileSize = string.Format("{0}KB", ((double)size / 1024).ToString(".##"));
- else if (size == 0)
- FileSize = "0 Byte";
- else
- FileSize = string.Format("{0}Byte", ((double)size / 1).ToString(".##"));
- return FileSize;
- }
- //该片段来自于http://www.codesnippet.cn/detail/010820134906.html
来源: http://www.codesnippet.cn/detail/010820134906.html