【问题标题】:How can I give the number two decimal in my template? [duplicate]如何在模板中给出小数点后两位? [复制]
【发布时间】:2018-03-02 18:18:17
【问题描述】:

我在模板中使用了 total_prices

{{ data.total_prices }}  # there shows 300

但是我怎样才能给它两个浮点数呢?

我的意思是它看起来像模板中的300.00

如何处理?

【问题讨论】:

    标签: python django django-templates


    【解决方案1】:

    使用floatformat 模板过滤器,

    {{ data.total_prices|floatformat:-2 }}  # now it shows 300.00
    

    【讨论】:

      猜你喜欢
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      相关资源
      最近更新 更多