在Python中用verbally格式化数字

pythonistas如何将数字作为单词打印,就像Common Lisp代码的等价物一样:

[3]> (format t "~r" 1e25)
nine septillion, nine hundred and ninety-nine sextillion, nine hundred and ninety-nine quintillion, seven hundred and seventy-eight quadrillion, one hundred and ninety-six trillion, three hundred and eight billion, three hundred and sixty-one million, two hundred and sixteen thousand

解决方法:

没有在python核心,但有第三方库num2words

>>> from num2words import num2words
>>> num2words(1e25)
'ten septillion, one billion, seventy-three million, seven hundred and forty-one thousand, eight hundred and twenty-four'

>>> num2words(10000000000000000000000000)
'ten septillion'

(请注意,1e25未精确转换为整数,在您的示例中均未转换为整数)

相关文章

python方向·数据分析   ·自然语言处理nlp   案例:中...
原文地址http://blog.sina.com.cn/s/blog_574a437f01019poo....
ptb数据集是语言模型学习中应用最广泛的数据集,常用该数据集...
 Newtonsoft.JsonNewtonsoft.Json是.Net平台操作Json的工具...
NLP(NaturalLanguageProcessing)自然语言处理是人工智能的一...
做一个中文文本分类任务,首先要做的是文本的预处理,对文本...