fix(stringutil): use InvariantCulture for byte-size formatting
Locale-Bug: BytesToString rendert auf deutscher Locale "1,5GB" statt "1.5GB". InvariantCulture pinnt den Dezimal-Separator. Plus InternalsVisibleTo-Hook für ein lokales (gitignored) Test-Projekt.
This commit is contained in:
@@ -36,6 +36,13 @@
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="[3.1.12, 4.0.0)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Pure-function test suites in HellionChat.Tests need access to
|
||||
the internal helper classes (StringUtil, UriPayload, Tokenizer
|
||||
etc.). Test assembly does not get redistributed. -->
|
||||
<InternalsVisibleTo Include="HellionChat.Tests" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Resources\Language.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace HellionChat.Util;
|
||||
@@ -24,7 +25,8 @@ internal static class StringUtil
|
||||
var place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
|
||||
var num = Math.Round(bytes / Math.Pow(1024, place), 1);
|
||||
// "0.#" keeps the rounded fractional digit (1.5 GB stays "1.5GB"); "N0"
|
||||
// would truncate it back to integer.
|
||||
return (Math.Sign(byteCount) * num).ToString("0.#") + suf[place];
|
||||
// would truncate it back to integer. InvariantCulture pins the decimal
|
||||
// separator to '.' so a German locale doesn't render "1,5GB".
|
||||
return (Math.Sign(byteCount) * num).ToString("0.#", CultureInfo.InvariantCulture) + suf[place];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user