Django模板如何将数字转换为单词 [英] Django template How to Convert numbers to Words

查看:342
本文介绍了Django模板如何将数字转换为单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在搜索一个模板标签,将值转换为522到五百二十二。查看文档我遇到了

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

django.contrib.humanize

其中有一个内置的标签intword,但它只适用于数字大于一百万的数字。

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

作为替代解决方案,我创建了一个标签使用函数
Python脚本从数字转换为单词以进行打印检查

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.

推荐答案

查看此图书馆: num2words

直接从文档:

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

这篇关于Django模板如何将数字转换为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆