mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
early continue
skip processing given power of thousand if it is 0
This commit is contained in:
@@ -130,6 +130,10 @@ class Num2Word_CZ(Num2Word_Base):
|
||||
i = len(chunks)
|
||||
for x in chunks:
|
||||
i -= 1
|
||||
|
||||
if x == 0:
|
||||
continue
|
||||
|
||||
n1, n2, n3 = get_digits(x)
|
||||
|
||||
if n3 > 0:
|
||||
@@ -143,7 +147,7 @@ class Num2Word_CZ(Num2Word_Base):
|
||||
elif n1 > 0 and not (i > 0 and x == 1):
|
||||
words.append(ONES[n1][0])
|
||||
|
||||
if x > 0 and i > 0:
|
||||
if i > 0:
|
||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||
|
||||
return ' '.join(words)
|
||||
|
||||
@@ -94,9 +94,11 @@ def int2word(n):
|
||||
i = len(chunks)
|
||||
for x in chunks:
|
||||
i -= 1
|
||||
n1, n2, n3 = get_digits(x)
|
||||
|
||||
# print str(n3) + str(n2) + str(n1)
|
||||
if x == 0:
|
||||
continue
|
||||
|
||||
n1, n2, n3 = get_digits(x)
|
||||
|
||||
if n3 > 0:
|
||||
if n3 <= 2:
|
||||
@@ -113,7 +115,7 @@ def int2word(n):
|
||||
elif n1 > 0 and not (i > 0 and x == 1):
|
||||
words.append(ONES[n1][0])
|
||||
|
||||
if x > 0 and i > 0:
|
||||
if i > 0:
|
||||
if i <= 2:
|
||||
words.append(THOUSANDS[i][0])
|
||||
else:
|
||||
|
||||
@@ -149,6 +149,10 @@ class Num2Word_LT(Num2Word_Base):
|
||||
|
||||
for x in chunks:
|
||||
i -= 1
|
||||
|
||||
if x == 0:
|
||||
continue
|
||||
|
||||
n1, n2, n3 = get_digits(x)
|
||||
|
||||
if n3 > 0:
|
||||
@@ -169,7 +173,7 @@ class Num2Word_LT(Num2Word_Base):
|
||||
else:
|
||||
words.append(ONES[n1][0])
|
||||
|
||||
if x > 0 and i > 0:
|
||||
if i > 0:
|
||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||
|
||||
return ' '.join(words)
|
||||
|
||||
@@ -157,6 +157,10 @@ class Num2Word_LV(Num2Word_Base):
|
||||
i = len(chunks)
|
||||
for x in chunks:
|
||||
i -= 1
|
||||
|
||||
if x == 0:
|
||||
continue
|
||||
|
||||
n1, n2, n3 = get_digits(x)
|
||||
|
||||
if n3 > 0:
|
||||
@@ -176,7 +180,7 @@ class Num2Word_LV(Num2Word_Base):
|
||||
elif n1 > 0 and not (i > 0 and x == 1):
|
||||
words.append(ONES[n1][0])
|
||||
|
||||
if x > 0 and i > 0:
|
||||
if i > 0:
|
||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||
|
||||
return ' '.join(words)
|
||||
|
||||
@@ -141,6 +141,10 @@ class Num2Word_PL(Num2Word_Base):
|
||||
i = len(chunks)
|
||||
for x in chunks:
|
||||
i -= 1
|
||||
|
||||
if x == 0:
|
||||
continue
|
||||
|
||||
n1, n2, n3 = get_digits(x)
|
||||
|
||||
if n3 > 0:
|
||||
@@ -154,7 +158,7 @@ class Num2Word_PL(Num2Word_Base):
|
||||
elif n1 > 0 and not (i > 0 and x == 1):
|
||||
words.append(ONES[n1][0])
|
||||
|
||||
if x > 0 and i > 0:
|
||||
if i > 0:
|
||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||
|
||||
return ' '.join(words)
|
||||
|
||||
@@ -209,6 +209,10 @@ class Num2Word_RU(Num2Word_Base):
|
||||
i = len(chunks)
|
||||
for x in chunks:
|
||||
i -= 1
|
||||
|
||||
if x == 0:
|
||||
continue
|
||||
|
||||
n1, n2, n3 = get_digits(x)
|
||||
|
||||
if n3 > 0:
|
||||
@@ -223,7 +227,7 @@ class Num2Word_RU(Num2Word_Base):
|
||||
ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES
|
||||
words.append(ones[n1][0])
|
||||
|
||||
if x > 0 and i > 0:
|
||||
if i > 0:
|
||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||
|
||||
return ' '.join(words)
|
||||
|
||||
@@ -147,6 +147,10 @@ class Num2Word_UK(Num2Word_Base):
|
||||
i = len(chunks)
|
||||
for x in chunks:
|
||||
i -= 1
|
||||
|
||||
if x == 0:
|
||||
continue
|
||||
|
||||
n1, n2, n3 = get_digits(x)
|
||||
|
||||
if n3 > 0:
|
||||
@@ -162,7 +166,7 @@ class Num2Word_UK(Num2Word_Base):
|
||||
ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES
|
||||
words.append(ones[n1][0])
|
||||
|
||||
if x > 0 and i > 0:
|
||||
if i > 0:
|
||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||
|
||||
return ' '.join(words)
|
||||
|
||||
@@ -53,9 +53,6 @@ class Num2WordsLTTest(TestCase):
|
||||
'minus penki tūkstančiai kablelis dvidešimt du',
|
||||
)
|
||||
|
||||
# print(fill(n2w(1000000000000000000000000000000)))
|
||||
# naintilijonas
|
||||
|
||||
def test_to_ordinal(self):
|
||||
# @TODO: implement to_ordinal
|
||||
with self.assertRaises(NotImplementedError):
|
||||
|
||||
@@ -48,9 +48,6 @@ class Num2WordsLVTest(TestCase):
|
||||
'mīnus pieci tūkstoši komats divdesmit divi',
|
||||
)
|
||||
|
||||
# >>> print(fill(n2w(1000000000000000000000000000000)))
|
||||
# nontiljons
|
||||
|
||||
self.assertEqual(num2words(0, lang='lv'), 'nulle')
|
||||
self.assertEqual(num2words(5, lang='lv'), "pieci")
|
||||
self.assertEqual(num2words(15, lang='lv'), "piecpadsmit")
|
||||
|
||||
Reference in New Issue
Block a user