我想将100
或One Hundred
或任何数字转换为其等效字符串。
我想避免写一个冗长的程序。最好的方法是什么?
答案 0 :(得分:8)
您可以使用humanize
:https://pypi.python.org/pypi/humanize
>>> import humanize
>>> humanize.intcomma(12345)
'12,345'
>>> humanize.intword(123455913)
'123.5 million'
>>> humanize.intword(12345591313)
'12.3 billion'
>>> humanize.apnumber(4)
'four'
>>> humanize.apnumber(41)
'41'
答案 1 :(得分:2)
您可以使用humanize
>>> import humanize
>>> humanize.intword(100)
'One Hundred'
您也可以尝试使用pynum2word
>>> import num2word
>>> num2word.to_card(15)
'fifteen'
答案 2 :(得分:0)
我终于在python中使用了inflect库。
我只是,
import inflect
i = inflect.engine()
print i.number_to_words(number)
其余的答案更好,但这对我来说效果最好。