From 98160be3e4d6fe32e408a3c09b4880ffced768c4 Mon Sep 17 00:00:00 2001 From: Tkael Date: Tue, 29 Dec 2020 23:53:00 -0800 Subject: [PATCH] Tidy up Humanise() --- SpeechService/Translations.cs | 9 ++++++++- Tests/SpeechUnitTests.cs | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/SpeechService/Translations.cs b/SpeechService/Translations.cs index b52453cffb..1ce19923e0 100644 --- a/SpeechService/Translations.cs +++ b/SpeechService/Translations.cs @@ -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 diff --git a/Tests/SpeechUnitTests.cs b/Tests/SpeechUnitTests.cs index cddff01cfd..5543c28fca 100644 --- a/Tests/SpeechUnitTests.cs +++ b/Tests/SpeechUnitTests.cs @@ -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]