我有一个从数据库中取数据的变量
{{i.rewardpoints}}
和它返回的值,如1.799或12,db有多个值,包含小数,没有小数
但我需要显示没有小数的值
我该怎么做
答案 0 :(得分:2)
舍入到最接近的整数:
{{ i.rewardpoints|floatformat:"0" }}
获取整数部分:
{{ i.rewardpoints|stringformat:"d" }}
In [19]: tpl = Template('{{ x|stringformat:"d" }} {{ x|floatformat:"0" }}')
In [20]: tpl.render(Context({'x': 1.1}))
Out[20]: u'1 1'
In [21]: tpl.render(Context({'x': 1.9}))
Out[21]: u'1 2'