Skip to content

Commit 81ee072

Browse files
Pin culture of the size formatter
1 parent fae5ce0 commit 81ee072

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Modules/DirectoryBrowsing/Provider/FileSizeFormatter.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23

34
namespace GenHTTP.Modules.DirectoryBrowsing.Provider
45
{
@@ -22,19 +23,19 @@ public static string Format(ulong? bytes)
2223

2324
if (bytes > TERABYTES)
2425
{
25-
return Math.Round(b / TERABYTES, 2) + " TB";
26+
return Math.Round(b / TERABYTES, 2).ToString(CultureInfo.InvariantCulture) + " TB";
2627
}
2728
if (bytes > GIGABYTES)
2829
{
29-
return Math.Round(b / GIGABYTES, 2) + " GB";
30+
return Math.Round(b / GIGABYTES, 2).ToString(CultureInfo.InvariantCulture) + " GB";
3031
}
3132
else if (bytes > MEGABYTES)
3233
{
33-
return Math.Round(b / MEGABYTES, 2) + " MB";
34+
return Math.Round(b / MEGABYTES, 2).ToString(CultureInfo.InvariantCulture) + " MB";
3435
}
3536
else if (bytes > KILOBYTES)
3637
{
37-
return Math.Round(b / KILOBYTES, 2) + " KB";
38+
return Math.Round(b / KILOBYTES, 2).ToString(CultureInfo.InvariantCulture) + " KB";
3839
}
3940

4041
return $"{bytes} Bytes";

Testing/Acceptance/Modules/DirectoryBrowsing/FormatterTest.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public void TestFormatting()
1313
{
1414
Assert.AreEqual("512 Bytes", FileSizeFormatter.Format(512));
1515

16-
Assert.AreEqual("2,78 KB", FileSizeFormatter.Format(2842));
16+
Assert.AreEqual("2.78 KB", FileSizeFormatter.Format(2842));
1717

18-
Assert.AreEqual("2,78 MB", FileSizeFormatter.Format(2842 * 1024));
18+
Assert.AreEqual("2.78 MB", FileSizeFormatter.Format(2842 * 1024));
1919

20-
Assert.AreEqual("2,78 GB", FileSizeFormatter.Format(2842L * 1024 * 1024));
20+
Assert.AreEqual("2.78 GB", FileSizeFormatter.Format(2842L * 1024 * 1024));
2121

22-
Assert.AreEqual("2,78 TB", FileSizeFormatter.Format(2842L * 1024 * 1024 * 1024));
22+
Assert.AreEqual("2.78 TB", FileSizeFormatter.Format(2842L * 1024 * 1024 * 1024));
2323
}
2424

2525
}

0 commit comments

Comments
 (0)