无法使用jinja2将浮点数舍入为整数 [英] Cannot round float to integer using jinja2
本文介绍了无法使用jinja2将浮点数舍入为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在尝试获取jina2模板进行舍入时出现问题.我真的不介意会发生什么,因为我的所有数字都是通过将小数乘以小于1(例如0.31
)再乘以100
来产生的.所以我有31.0
.我想删除小数点后的位置,但似乎没有任何作用:
Have issues trying to get the jina2 template to perform a rounding. I don't really mind what happens, as all my numbers have been produced by multiplying a decimal less then 1 (e.g. 0.31
) then multiplied by 100
. So I have 31.0
. I want to drop the decimal place, but nothing appears to work:
{{row.score.combined*100|float|round(0, 'floor')}}
或更简单:
{{row.score.combined*100|int}}
甚至:
{{row.score.combined*100|round|int}}
在所有情况下我仍然得到31.0.
I still get 31.0 in all cases.
推荐答案
需要在方括号中加上乘法.四舍五入仅发生在100.
Requires brackets around the multiplication. Rounding was only occurring on the 100.
{{(row.score.combined*100)|int}}
这篇关于无法使用jinja2将浮点数舍入为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文