diff --git a/src/Humanizer.Tests.Shared/MetricNumeralTests.cs b/src/Humanizer.Tests.Shared/MetricNumeralTests.cs index 252a753d2..386e5fcf5 100644 --- a/src/Humanizer.Tests.Shared/MetricNumeralTests.cs +++ b/src/Humanizer.Tests.Shared/MetricNumeralTests.cs @@ -101,8 +101,9 @@ public void TestAllSymbolsAsInt(int exponent) [InlineData("12.34k", 12345, false, true, 2)] [InlineData("12k", 12345, false, true, 0)] [InlineData("-3.9m", -3.91e-3, false, true, 1)] + [InlineData("10 ", 10, true, false, 0)] public void ToMetric(string expected, double input, bool hasSpace, bool useSymbol, int? decimals) - { + { Assert.Equal(expected, input.ToMetric(hasSpace, useSymbol, decimals)); } diff --git a/src/Humanizer/MetricNumeralExtensions.cs b/src/Humanizer/MetricNumeralExtensions.cs index 5ce9a3e2d..5f8609637 100644 --- a/src/Humanizer/MetricNumeralExtensions.cs +++ b/src/Humanizer/MetricNumeralExtensions.cs @@ -221,9 +221,12 @@ private static string ReplaceNameBySymbol(string input) private static string BuildRepresentation(double input, bool hasSpace, bool useSymbol, int? decimals) { var exponent = (int)Math.Floor(Math.Log10(Math.Abs(input)) / 3); - return exponent.Equals(0) - ? input.ToString() - : BuildMetricRepresentation(input, exponent, hasSpace, useSymbol, decimals); + + if (exponent.Equals(0)) + { + return hasSpace ? string.Concat(input, " ") : input.ToString(); + } + return BuildMetricRepresentation(input, exponent, hasSpace, useSymbol, decimals); } ///