Django template How to Convert numbers to Words

我只是一个虾纸丫 提交于 2019-12-11 02:25:26

问题


I am searching for a template tag to convert a value like 522 to five hundred twenty two only. Looking in docs i came across

django.contrib.humanize

which has a build in tag intword but it works only with number with numbers greater than a million.

as a alternative solution i have created a tag using function from Python script to convert from numbers to words for printing cheques

kindly suggest if any better solution possible.


回答1:


Check out this library: num2words

Straight from the docs:

>>> from num2words import num2words
>>> num2words(42)
forty-two
>>> num2words(42, ordinal=True)
forty-second
>>> num2words(42, lang='fr')
quarante-deux


来源:https://stackoverflow.com/questions/37914941/django-template-how-to-convert-numbers-to-words

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!