如何获得小数位字段以在模板中显示更多小数位? [英] How can I get a decimal field to show more decimal places in a template?

查看:91
本文介绍了如何获得小数位字段以在模板中显示更多小数位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

price_a = models.DecimalField(max_digits=5, decimal_places=3)

示例价格:95,90

Example price: 95,90

在我的模板中:

{{ price_a }}

它仅显示95,9。如何显示全价(尾随0:95,90)?

it display only 95,9. How can I get it to display full price (with an extra trailing 0: 95,90)?

推荐答案

使用 floatformat 模板过滤器

Use the floatformat template filter, for example

{{ price_a|floatformat:2 }}

这篇关于如何获得小数位字段以在模板中显示更多小数位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆