我如何在不使用过滤器的情况下在Django模板中取整值 [英] How can i round a value in django template without using the filter
本文介绍了我如何在不使用过滤器的情况下在Django模板中取整值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以在Django模板中执行某些 python数学函数。实际上,我需要舍入一个变量值,并且想要不使用过滤器就可以实现这一点。
Is there any way that I can do some python math function in django template. Actually I need to round a variable value and I want to achieve this without using the filters.
例如 {{math.round(total )}}
。
推荐答案
您可以使用 floatformat 舍入到django模板中的值。
You can use floatformat to round of the value in django template.
{{ total|floatformat }}
如果需要要执行更多数学运算,您可以尝试 django-mathfilters 。或者,您可以编写自定义模板标签并执行操作在该模板标签中。
If you want to perform more mathematical operations, you can try django-mathfilters. Or you could write your custom template tag and perform the operations in that template tag.
这篇关于我如何在不使用过滤器的情况下在Django模板中取整值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文