123456789101112131415161718192021222324252627282930 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace QVCopier.Utility
- {
- public static class TextFormatter
- {
- public static string ToFriendFileSize(this long value)
- {
- string[] sizes = { "B", "KB", "MB", "GB", "TB" };
- double len = value;
- var order = 0;
- while (len >= 1024 && order < sizes.Length - 1)
- {
- order++;
- len = len / 1024;
- }
- // Adjust the format string to your preferences. For example "{0:0.#}{1}" would
- // show a single decimal place, and no space.
- var result = $"{len:0.##} {sizes[order]}";
- return result;
- }
- }
- }
|