early continue

skip processing given power of thousand if it is 0
This commit is contained in:
Marek Madejski
2018-12-03 16:07:15 +01:00
parent d78add4c3a
commit 4a0b323fa9
9 changed files with 35 additions and 15 deletions

View File

@@ -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)

View File

@@ -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:

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)