如何在不使用过滤器的情况下舍入 django 模板中的值 [英] How can i round a value in django template without using the filter

查看:19
本文介绍了如何在不使用过滤器的情况下舍入 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屋!

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