You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
476 B

2 years ago
  1. using System;
  2. namespace EasyBL
  3. {
  4. public class FileService
  5. {
  6. public static string ToKMGTByte(string file_size)
  7. {
  8. string[] suffixes = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
  9. var s = 0;
  10. var size = Convert.ToInt64(file_size);
  11. while (size >= 1024)
  12. {
  13. s++;
  14. size /= 1024;
  15. }
  16. return $"{size}{suffixes[s]}";
  17. }
  18. }
  19. }