简体   繁体   English

如何在不改变符号位置的情况下过滤货币

[英]How to filter currency without changing position of the symbol

i am having this problem:我有这个问题:

{{100 | currency:'‎€'}} 

the output is fine 100 ‎€ , but when i change the language for example en-US culture, the symbol changes its position so it becomes ‎€ 100 .输出很好100 € ,但是当我更改语言(例如 en-US 文化)时,符号会改变其位置,因此变为€ 100

What i want is that symbol stays on its position even language is changed.我想要的是,即使语言改变了,符号也能保持在它的位置上。 i can do like:我可以这样做:

{{100 | currency:'‎'}} {{'‎€'}} 

but in that case if i have $ as currency, it will be 100$ not $100.但在那种情况下,如果我有美元作为货币,它将是100 美元而不是 100 美元。

So i don't want hard coded stuff, i would like to have dynamic filter that will set place of its symbol in one place.所以我不想要硬编码的东西,我想要动态过滤器,将其符号的位置设置在一个地方。

Thanks in advance.提前致谢。

You can implement your custom filter like您可以实现您的自定义过滤器,

app.filter('customCurrency', function () {
return function (value) {

    // Do your logic here and append your currency
    // symbol before or after of your value as per your requirement

    return value
}; });

You can implement your own filter or directive, but I think the better approach would be to set the locale on Angular using l10n.您可以实现自己的过滤器或指令,但我认为更好的方法是使用 l10n 在 Angular 上设置语言环境。

i18n and l10n i18n 和 l10n

And if you need to force a change of localization from europe to en-Us you can do it programmatically, this make sense because you need to convert EUR to USD$.如果您需要强制将本地化从欧洲更改为 en-Us,您可以以编程方式进行,这是有道理的,因为您需要将 EUR 转换为 USD$。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM