在 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
How do pythonistas print a number as words, like the equivalent of the Common Lisp code:
[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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
python 核心中没有,但有第 3 方库 num2words
(请注意,1e25 并未精确转换为整数,在你的例子中都没有)
no in python core, but there is 3rd party library num2words
(note that 1e25 is not converted to integer precisely, neither in your example)
我刚刚开始用土耳其语工作,这可能会有所帮助。
并且
它返回一个字符串列表, 带有简单的测试函数
randomizer()
prettizer()
和核心函数humanizer()
它可以处理非常大的数字,因为它没有使用分割方法,但使用字符串分割和操作。
您可以输入偶数或字符串。
由于我没有写数字验证,它甚至可以处理非数字文本
:)
I just started a work in Turkish, it may be helpful.
https://github.com/guneysus/humanizer-tr
It return a list of strings, and comes with easy testing functions
randomizer()
prettizer()
and the core functionhumanizer()
It may handle very large numbers because it did not use dividing approach, but uses string segmentation and manipulation.
You can enter even number or string.
Since i did not write a number verification it can even handle a non number text
:)
这是一种实现方法:
它是这样做的:
Here as a way to do it:
It does this: