http://www.easysurf.cc/cnvert18.htm 试图将数字扼杀变成一个english,但它们正在带来自然的稳健产出。
For example, on http://www.easysurf.cc/cnvert18.htm:
[in]: 100456
[out]: one hundred thousand four hundred fifty-six
http://www.calculator.org/calculate-online/mathematics/text- number.aspx” rel=“nofollow” http://www.calculator.org/calculate-online/mathematics/text- number.aspx:
[in]: 100456
[out]: one hundred thousand, four hundred and fifty-six
[in]: 10123124001
[out]: ten billion, one hundred and twenty-three million, one hundred and twenty-four thousand, one
但是,它在某些时候打破了:
[in]: 10000000001
[out]: ten billion, , , one
I ve撰写了我自己的版本,但涉及许多规则,从:
import codecs
def num2word (num):
ones = {1:"one",2:"two",3:"three",4:"four",
5:"five",6:"six",7:"seven",8:"eight",
9:"nine",0:"zero",10:"ten"}
teens = {11:"eleven",12:"twelve",13:"thirteen",
14:"fourteen",15:"fifteen"}
tens = {2:"twenty",3:"thirty",4:"forty",
5:"fifty",6:"sixty",7:"seventy",
8:"eighty",9:"ninety"}
lens = {3:"hundred",4:"thousand",6:"hundred",7:"million",
8:"million", 9:"million",10:"billion"#,13:"trillion",11:"googol",
}
if num > 999999999:
return "Number more than 1 billion"
# Ones
if num < 11:
return ones[num]
# Teens
if num < 20:
word = ones[num%10] + "teen" if num > 15 else teens[num]
return word
# Tens
if num > 19 and num < 100:
word = tens[int(str(num)[0])]
if str(num)[1] == "0":
return word
else:
word = word + " " + ones[num%10]
return word
# First digit for thousands,hundred-thousands.
if len(str(num)) in lens and len(str(num)) != 3:
word = ones[int(str(num)[0])] + " " + lens[len(str(num))]
else:
word = ""
# Hundred to Million
if num < 1000000:
# First and Second digit for ten thousands.
if len(str(num)) == 5:
word = num2word(int(str(num)[0:2])) + " thousand"
# How many hundred-thousand(s).
if len(str(num)) == 6:
word = word + " " + num2word(int(str(num)[1:3])) +
" " + lens[len(str(num))-2]
# How many hundred(s)?
thousand_pt = len(str(num)) - 3
word = word + " " + ones[int(str(num)[thousand_pt])] +
" " + lens[len(str(num))-thousand_pt]
# Last 2 digits.
last2 = num2word(int(str(num)[-2:]))
if last2 != "zero":
word = word + " and " + last2
word = word.replace(" zero hundred","")
return word.strip()
left, right = ,
# Less than 1 million.
if num < 100000000:
left = num2word(int(str(num)[:-6])) + " " + lens[len(str(num))]
right = num2word(int(str(num)[-6:]))
# From 1 million to 1 billion.
if num > 100000000 and num < 1000000000:
left = num2word(int(str(num)[:3])) + " " + lens[len(str(num))]
right = num2word(int(str(num)[-6:]))
if int(str(num)[-6:]) < 100:
word = left + " and " + right
else:
word = left + " " + right
word = word.replace(" zero hundred","").replace(" zero thousand"," thousand")
return word
print num2word(int(raw_input("Give me a number:
")))
www.un.org/Depts/DGACM/index_spanish.htm 我怎样才能使文字一号书写接受>ill
?。
www.un.org/Depts/DGACM/index_spanish.htm 是否还有其他办法获得同样的产出?
www.un.org/Depts/DGACM/index_spanish.htm 我的法典能否用较少的手法书写?