python - 在 Python 中口头格式化数字

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 核心中没有,但有 3rd 方库 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 并未精确转换为整数)

https://stackoverflow.com/questions/3158132/

相关文章:

html - Crystal Report 显示 HTML 文本,但不显示项目符号。为什么?

c++ - printf() 中宽度小于精度的意义何在?

linq - ReSharper LINQ 扩展方法格式化

R - 绘图标签文本的文本格式 - 删除线

formatting - 从 Mathematica 导出自定义格式的表达式

mysql - 如何将 MySQL 结果以表格式存储到文件中

sql-server-2005 - 在 SQL Reporting 2005 中更改货币符号

string - 什么函数用于格式化/替换 Grails/Groovy 中字符串中的 {0} {1}

haskell - 将 NominalDiffTime 打印为小时、分钟和秒

c - 是否有 "null"printf 代码不打印任何内容,用于跳过参数?