Skip to content

Commit

Permalink
fixes #772
Browse files Browse the repository at this point in the history
  • Loading branch information
ich committed Feb 19, 2019
1 parent d5b3cf3 commit 57a06a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Humanizer.Tests.Shared/MetricNumeralTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
9 changes: 6 additions & 3 deletions src/Humanizer/MetricNumeralExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down

0 comments on commit 57a06a6

Please sign in to comment.