correction on lang_DE: ordnum, plural and ord form of >= 10**6

This commit is contained in:
isnani
2015-12-12 16:54:30 +01:00
parent 848f9d26b1
commit 797e74d1fc
3 changed files with 61 additions and 23 deletions

View File

@@ -101,7 +101,6 @@ class Num2Word_Base(object):
if value >= self.MAXVAL:
raise OverflowError(self.errmsg_toobig % (value, self.MAXVAL))
val = self.splitnum(value)
words, num = self.clean(val)

View File

@@ -26,7 +26,6 @@ class Num2Word_DE(Num2Word_EU):
self.cards[10**n] = word + "illiarde"
self.cards[10**(n-3)] = word + "illion"
def setup(self):
self.negword = "minus "
self.pointword = "Komma"
@@ -49,14 +48,19 @@ class Num2Word_DE(Num2Word_EU):
"zw\xF6lf", "elf", "zehn", "neun", "acht", "sieben",
"sechs", "f\xFCnf", "vier", "drei", "zwei", "eins",
"null"]
self.ords = { "eins" : "ers",
"drei" : "drit",
"acht" : "ach",
"sieben" : "sieb",
"ig" : "igs" }
self.ords = {"eins": "ers",
"drei": "drit",
"acht": "ach",
"sieben": "sieb",
"ig": "igs",
"ert": "erts",
"end": "ends",
"ion": "ions",
"nen": "nens",
"rde": "rdes",
"rden": "rdens"}
self.ordflag = False
def merge(self, curr, next):
ctext, cnum, ntext, nnum = curr + next
@@ -69,41 +73,35 @@ class Num2Word_DE(Num2Word_EU):
if nnum >= 10**6:
if cnum > 1:
if ntext.endswith("e") or self.ordflag:
ntext += "s"
ntext += "n"
else:
ntext += "es"
ntext += "en"
ctext += " "
val = cnum * nnum
else:
if nnum < 10 < cnum < 100:
if nnum == 1:
ntext = "ein"
ntext, ctext = ctext, ntext + "und"
ntext, ctext = ctext, ntext + "und"
elif cnum >= 10**6:
ctext += " "
val = cnum + nnum
word = ctext + ntext
return (word, val)
def to_ordinal(self, value):
self.verify_ordinal(value)
self.ordflag = True
outword = self.to_cardinal(value)
self.ordflag = False
for key in self.ords:
if outword.endswith(key):
outword = outword[:len(outword) - len(key)] + self.ords[key]
break
return outword + "te"
# Is this correct??
def to_ordinal_num(self, value):
self.verify_ordinal(value)
return str(value) + "te"
return str(value) + "."
def to_currency(self, val, longval=True, old=False):
if old:
@@ -117,8 +115,6 @@ class Num2Word_DE(Num2Word_EU):
return self.to_cardinal(val)
return self.to_splitnum(val, hightxt="hundert", longval=longval)
n2w = Num2Word_DE()
to_card = n2w.to_cardinal
to_ord = n2w.to_ordinal
@@ -126,15 +122,20 @@ to_ordnum = n2w.to_ordinal_num
def main():
for val in [ 1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155,
for val in [1, 7, 8, 12, 17, 81, 91, 99, 100, 101, 102, 155,
180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000,
8280, 8291, 150000, 500000, 1000000, 2000000, 2000001,
8280, 8291, 150000, 500000, 3000000, 1000000, 2000001, 1000000000, 2000000000,
-21212121211221211111, -2.121212, -1.0000100]:
n2w.test(val)
n2w.test(1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
# n2w.test(1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
n2w.test(3000000)
n2w.test(3000000000001)
n2w.test(3000000324566)
print n2w.to_currency(112121)
print n2w.to_year(2000)
print n2w.to_year(1820)
print n2w.to_year(2001)
if __name__ == "__main__":
main()