2013-04-01 99 views
2

我具有從數據庫獲取數據拆分在Django

{{i.rewardpoints}}

並將它返回諸如1.799或12分貝具有值的變量其中包含小數和無小數

但多個值我需要顯示值無小數

我怎麼能做到這一點

回答

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' 
+0

GREAT非常感謝 – user2106353

+0

但它的價值,我不希望出現這種情況,我只想值的第一個部分之前十進制 – user2106353

+0

我可以扣除1從{{i.rewardpoints只是ROUND | floatformat:「0」 }} – user2106353