开发者

Django and floatformat tag

I wa开发者_如何学Cnt to modify / change the way the floatformat works.

By default it changes the input decimal as such:

{{ 1.00|floatformat }} -> 1
{{ 1.50|floatformat }} -> 1.5
{{ 1.53|floatformat }} -> 1.53

I want to change this abit as such: If there is a floating part, it should keep the first 2 floating digits. If no floating (which means .00) it should simply cut out the floating part. IE:

{{ 1.00|floatformat }} -> 1
{{ 1.50|floatformat }} -> 1.50
{{ 1.53|floatformat }} -> 1.53


Doesn't using a parameter of -2, as described in the docs you link to, do what you want?

{{ 1.00|floatformat:-2 }}

See Django Docs: https://docs.djangoproject.com/en/2.0/ref/templates/builtins/#floatformat

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜