From c765a51567ea31aff4497c96a2e3687e1587dd96 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 13 Sep 2026 11:26:31 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=90=E3=82=A4=E3=83=88=E6=95=B0=E3=81=AE?= =?UTF-8?q?=E8=A1=A8=E8=A8=98=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyForge/ViewModels/ByteText.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ProxyForge/ViewModels/ByteText.cs diff --git a/ProxyForge/ViewModels/ByteText.cs b/ProxyForge/ViewModels/ByteText.cs new file mode 100644 index 0000000..5d1a58d --- /dev/null +++ b/ProxyForge/ViewModels/ByteText.cs @@ -0,0 +1,24 @@ +using System.Globalization; + +namespace ProxyForge.ViewModels; + +internal static class ByteText +{ + static readonly string[] Units = ["B", "KB", "MB", "GB", "TB"]; + + public static string Format(long bytes) + { + if (bytes <= 0) + return "0 B"; + + double value = bytes; + var order = 0; + while (value >= 1024d && order < Units.Length - 1) + { + value /= 1024d; + order++; + } + + return string.Create(CultureInfo.InvariantCulture, $"{value:0.##} {Units[order]}"); + } +}