diff --git a/mycroft/util/lang/format_en.py b/mycroft/util/lang/format_en.py index f04a7d3069..9597cc067c 100644 --- a/mycroft/util/lang/format_en.py +++ b/mycroft/util/lang/format_en.py @@ -319,13 +319,22 @@ def pronounce_number_en(num, places=2, short_scale=True, scientific=False): " and " + _sub_thousand(r) if r else "") def _short_scale(n): + if n > max(SHORT_SCALE_EN.keys()): + return "infinity" n = int(n) assert 0 <= n # TODO Some more or less obvious error to be fixed here - return ", ".join(reversed( - [_sub_thousand(z) + ( - " " + hundreds[i] if i else "") if z else "" - for i, z in enumerate(_split_by_thousands(n))])) + res = [] + for i, z in enumerate(_split_by_thousands(n)): + if not z: + continue + number = _sub_thousand(z) + if i: + number += " " + number += hundreds[i] + res.append(number) + + return " ".join(reversed(res)) def _split_by_thousands(n): assert 0 <= n @@ -336,7 +345,7 @@ def pronounce_number_en(num, places=2, short_scale=True, scientific=False): return res def _long_scale(n): - if n >= 10e153: + if n > max(LONG_SCALE_EN.keys()): return "infinity" n = int(n) assert 0 <= n diff --git a/test/unittests/util/test_format.py b/test/unittests/util/test_format.py index db33fe1918..2d69149fc8 100755 --- a/test/unittests/util/test_format.py +++ b/test/unittests/util/test_format.py @@ -186,6 +186,19 @@ class TestPronounceNumber(unittest.TestCase): "one point six seven two times ten to the power of " "negative twenty seven") + def test_large_numbers(self): + self.assertEqual(pronounce_number(299792458, short_scale=True), + "two hundred ninety nine million seven hundred ninety two thousand four hundred fifty eight") + self.assertEqual(pronounce_number(299792458, short_scale=False), + "two hundred ninety nine million seven hundred ninety two thousand four hundred fifty eight") + self.assertEqual(pronounce_number(100034000299792458, short_scale=True), + "one hundred quintillion thirty four quadrillion" + "two hundred ninety nine million seven hundred ninety two thousand four hundred fifty eight") + self.assertEqual(pronounce_number(100034000299792458, short_scale=False), + "one hundred trillion thirty four thousand billion" + "two hundred ninety nine million seven hundred ninety two thousand four hundred fifty eight") + + # def nice_time(dt, lang="en-us", speech=True, use_24hour=False, # use_ampm=False):