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.
22 lines
603 B
22 lines
603 B
using System.Diagnostics.CodeAnalysis; |
|
|
|
namespace StabilityMatrix.Core.Helper; |
|
|
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] |
|
public static class Size |
|
{ |
|
public const ulong KiB = 1024; |
|
public const ulong MiB = KiB * 1024; |
|
public const ulong GiB = MiB * 1024; |
|
|
|
public static string FormatBytes(ulong bytes) |
|
{ |
|
return bytes switch |
|
{ |
|
< KiB => $"{bytes} B", |
|
< MiB => $"{bytes / (double) KiB:0.0} KiB", |
|
< GiB => $"{bytes / (double) MiB:0.0} MiB", |
|
_ => $"{bytes / (double) GiB:0.0} GiB" |
|
}; |
|
} |
|
}
|
|
|