Django 千位分隔符用于模板中的产品价格

发布于 2024-10-29 07:10:08 字数 328 浏览 6 评论 0原文

我的产品价格以小数表示,

例如 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风疏影 2024-11-05 07:10:08

satchmo currency 过滤器需要可以转换为十进制的内容。但是,intcomma 返回一个字符串,并且由于它添加了千位分隔符,因此无法再将其转换为 Decimal。

解决方案是自己编写一个 currency_with_intcomma 模板过滤器,它首先运行 currency 过滤器,然后应用千位分隔符(您不能使用内置过滤器) ,你必须“manullay”来做)。

The satchmo currency filter requires something that can be converted into a Decimal. However intcomma 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 the currency filter and then applies the thousand separators (you can't use the builtin filter for that, you'll have to do it "manullay").

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文