mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
25 lines
785 B
C#
25 lines
785 B
C#
using System;
|
|
|
|
namespace Wabbajack.Common
|
|
{
|
|
public static class NumberExtensions
|
|
{
|
|
private static readonly string[]
|
|
Suffix = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; // Longs run out around EB
|
|
|
|
public static string ToFileSizeString(this long byteCount)
|
|
{
|
|
if (byteCount == 0)
|
|
return "0" + Suffix[0];
|
|
var bytes = Math.Abs(byteCount);
|
|
var place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
|
|
var num = Math.Round(bytes / Math.Pow(1024, place), 1);
|
|
return Math.Sign(byteCount) * num + Suffix[place];
|
|
}
|
|
|
|
public static string ToFileSizeString(this int byteCount)
|
|
{
|
|
return ToFileSizeString((long)byteCount);
|
|
}
|
|
}
|
|
} |