Django template How to Convert numbers to Words

2019-07-09 07:09发布

问题:

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