Verbally format a number in Python

前端 未结 3 713
春和景丽
春和景丽 2021-01-05 04:33

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 nin         


        
3条回答
  •  不思量自难忘°
    2021-01-05 05:22

    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 function humanizer()

    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 :)

    >>> humanizer('STACK OVER FLOW')
    ['STA Trilyon', 'CK  Milyar', 'OVE Milyon', 'R F Bin', 'LOW']
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题