Skip to content

Commit

Permalink
Tidy up Humanise()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkael committed Dec 30, 2020
1 parent ea1c9cc commit 98160be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion SpeechService/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,14 @@ public static string Humanize(decimal? value)
// See if we have a number whose value can be expressed with a short decimal (i.e 1.3 million)
if (number + ((decimal)nextDigit / 10) == Math.Round((decimal)value / orderMultiplier, 2))
{
return maybeMinus + (number + (decimal)nextDigit / 10) + order;
if (nextDigit == 0)
{
return maybeMinus + number * orderMultiplier;
}
else
{
return maybeMinus + (number + (decimal)nextDigit / 10) + order;
}
}

// Describe values for complex numbers where the largest order number does not exceed one hundred
Expand Down
4 changes: 2 additions & 2 deletions Tests/SpeechUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ public void TestSpeechHumanize6()
[TestMethod]
public void TestSpeechHumanize7()
{
Assert.AreEqual("minus 51 million", Translations.Humanize(-51000000));
Assert.AreEqual("minus 51000000", Translations.Humanize(-51000000));
}

[TestMethod]
public void TestSpeechHumanize8()
{
Assert.AreEqual("51 million", Translations.Humanize(51000001));
Assert.AreEqual("51000000", Translations.Humanize(51000001));
}

[TestMethod]
Expand Down

0 comments on commit 98160be

Please sign in to comment.