diff --git a/DigitalLearningSolutions.Web.Tests/Helpers/DisplayStringHelperTests.cs b/DigitalLearningSolutions.Web.Tests/Helpers/DisplayStringHelperTests.cs index 0379118d26..22ba9eaec8 100644 --- a/DigitalLearningSolutions.Web.Tests/Helpers/DisplayStringHelperTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Helpers/DisplayStringHelperTests.cs @@ -8,6 +8,7 @@ public class DisplayStringHelperTests { private const long Gibibyte = 1073741824; + private const long Mebibyte = 1048576; [Test] public void GenerateNumberWithLimitDisplayString_returns_expected_string_with_limit() @@ -46,7 +47,7 @@ public void FormatBytesWithLimit_returns_expected_string_for_kilobytes() var result = DisplayStringHelper.FormatBytesWithLimit(12, 1200); // Then - result.Should().Be("12B / 1.2KiB"); + result.Should().Be("12B / 1KB"); } [Test] @@ -56,7 +57,27 @@ public void FormatBytesWithLimit_returns_expected_string_for_gibibytes() var result = DisplayStringHelper.FormatBytesWithLimit(12, Gibibyte); // Then - result.Should().Be("12B / 1GiB"); + result.Should().Be("12B / 1GB"); + } + + [Test] + public void FormatBytesWithLimit_returns_expected_string_for_gibibytes_with_decimal() + { + // When + var result = DisplayStringHelper.FormatBytesWithLimit(12, Gibibyte + 500000000); + + // Then + result.Should().Be("12B / 1.5GB"); + } + + [Test] + public void FormatBytesWithLimit_returns_expected_string_for_mebibytes_with_decimal() + { + // When + var result = DisplayStringHelper.FormatBytesWithLimit(12, Mebibyte + 800000); + + // Then + result.Should().Be("12B / 2MB"); } [Test] @@ -69,7 +90,7 @@ public void FormatBytesWithLimit_returns_expected_string_when_less_than_next_siz var result = DisplayStringHelper.FormatBytesWithLimit(12, bytes); // Then - result.Should().Be("12B / 1024MiB"); + result.Should().Be("12B / 1024MB"); } [Test] diff --git a/DigitalLearningSolutions.Web.Tests/ViewModels/TrackingSystem/Centre/ContractDetailsViewModelTests.cs b/DigitalLearningSolutions.Web.Tests/ViewModels/TrackingSystem/Centre/ContractDetailsViewModelTests.cs index 57219d1ac8..34f571f0fe 100644 --- a/DigitalLearningSolutions.Web.Tests/ViewModels/TrackingSystem/Centre/ContractDetailsViewModelTests.cs +++ b/DigitalLearningSolutions.Web.Tests/ViewModels/TrackingSystem/Centre/ContractDetailsViewModelTests.cs @@ -40,7 +40,7 @@ public void AdminUsers_and_Centre_populate_expected_values() viewModel.TrainersColour.Should().Be("green"); viewModel.CustomCourses.Should().Be("10 / 12"); viewModel.CustomCoursesColour.Should().Be("yellow"); - viewModel.ServerSpace.Should().Be("1KiB / 1GiB"); + viewModel.ServerSpace.Should().Be("1KB / 1GB"); viewModel.ServerSpaceColour.Should().Be("green"); } diff --git a/DigitalLearningSolutions.Web/Helpers/DisplayStringHelper.cs b/DigitalLearningSolutions.Web/Helpers/DisplayStringHelper.cs index 5071e48ed7..a845171121 100644 --- a/DigitalLearningSolutions.Web/Helpers/DisplayStringHelper.cs +++ b/DigitalLearningSolutions.Web/Helpers/DisplayStringHelper.cs @@ -5,7 +5,7 @@ public static class DisplayStringHelper { private const string Divider = " / "; - private static readonly string[] Units = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB" }; + private static readonly string[] Units = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; public static string FormatNumberWithLimit(int number, int limit) { @@ -30,7 +30,9 @@ private static string GenerateBytesDisplayString(long byteCount) } var place = Convert.ToInt32(Math.Floor(Math.Log(byteCount, 1024))); - var number = Math.Round(byteCount / Math.Pow(1024, place), 1); + // Do not include decimal place below GB + var decimalPlaces = place <= 2 ? 0 : 1; + var number = Math.Round(byteCount / Math.Pow(1024, place), decimalPlaces); return (Math.Sign(byteCount) * number) + Units[place]; } }