简体   繁体   中英

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 .

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.

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.

i18n and 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$.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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