在模板中添加浮点数(Django) [英] add float number in template (django)

查看:77
本文介绍了在模板中添加浮点数(Django)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我遗漏了一些东西,但是我想添加一个浮点数,就像这样:

Maybe i'm missing something but i'm looking to add a float number, something like this:

{%floatnumber|add:3.4%}

过滤器添加我的结果,所以我不想编写过滤器,但是如果是唯一的方法,我将复制添加过滤器

Filter add round my result so I don't want to write my filter, but if is the only way, i'll copy add filter

现在我正在这样做:

def addf(value, arg):
    """Adds the arg to the value."""
    return float(value) + float(arg)
addf.is_safe = False
register.filter(addf)

推荐答案

现在,它将变成int.有一张公开票,我什至发送了补丁,但尚未提交;-) 这里是票证.

Right now it turns it into int. There is an open ticket and I even sent a patch, but it haven't been commited yet ;-) Here is the ticket.

这篇关于在模板中添加浮点数(Django)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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