FormattingHelper.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* Copyright (C) 2012-2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. namespace ISCSIConsole
  11. {
  12. public class FormattingHelper
  13. {
  14. public static string GetStandardSizeString(long value)
  15. {
  16. string[] suffixes = { " B", "KB", "MB", "GB", "TB", "PB", "EB" };
  17. int suffixIndex = 0;
  18. while (value > 9999)
  19. {
  20. value = value / 1024;
  21. suffixIndex++;
  22. }
  23. if (suffixIndex < suffixes.Length)
  24. {
  25. string FourCharacterValue = value.ToString();
  26. while (FourCharacterValue.Length < 4)
  27. {
  28. FourCharacterValue = " " + FourCharacterValue;
  29. }
  30. return String.Format("{0} {1}", FourCharacterValue, suffixes[suffixIndex]);
  31. }
  32. else
  33. {
  34. return "> 9999 EB";
  35. }
  36. }
  37. }
  38. }