Django 千位分隔符用于模板中的产品价格
我的产品价格以小数表示,
例如 15000.0000
现在我想在其上应用千位分隔符,intcomma
过滤器可以很好地处理小数如此处,
但之后我无法应用currency
过滤器,这意味着它不适用于货币过滤器。
我想要我的价格的最终输出:PKR 15,000.00
有什么建议可以得到这个吗?
谢谢 :)
i have the product price in decimals,
like 15000.0000
now i want to apply thousand separator on it, intcomma
filter works fine with decimals as here
but after it i can't apply currency
filter, means it didn't work with currency filter.
i want final output of my Price: PKR 15,000.00
any suggestions to get this?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
satchmo
currency
过滤器需要可以转换为十进制的内容。但是,intcomma
返回一个字符串,并且由于它添加了千位分隔符,因此无法再将其转换为 Decimal。解决方案是自己编写一个
currency_with_intcomma
模板过滤器,它首先运行currency
过滤器,然后应用千位分隔符(您不能使用内置过滤器) ,你必须“manullay”来做)。The satchmo
currency
filter requires something that can be converted into a Decimal. Howeverintcomma
returns a string, and since it adds the thousand separators, it can no longer be converted to a Decimal.The solution would be to write a
currency_with_intcomma
template filter yourself, which first runs through thecurrency
filter and then applies the thousand separators (you can't use the builtin filter for that, you'll have to do it "manullay").