How to specify locale different from default for currency with Angular currency filter?

Jimo

In our app we are using angular for i18n/l10n. It's working fine.

There's a problem though - sometimes the user needs to see info aligned with a locale, different from the current one. More specific - currency. E.g. - the user's locale is de-de and they open a catalog with item prices that are in US dollars. Of course, I can specify the currency symbol explicitly:

{{item.Price.Value | currency : "$" : 2 }}

but this is not a very graceful solution, because the user will see:

349,99 $

which is not the correct formatting. The correct one would be:

$349.99

So, I don't want to just change the currency symbol, but to change the whole currency formatting for a specific field and leave the remaining on the page localized according to the current locale.

Is it possible with the Angular currency filter or should I use my own custom filter?

Eleanor Zimmermann

After looking through the source code, I determined that Angular is using 'undefined' as the parameter trigger for the filter using default local currency. (see around line 14370 in Angular 1.2.15)

Thus, when chaining filters, you can get that default value by providing undefined as the parameter.

For you, the following should give you what you want:

{{item.Price.Value | currency : undefined : 2 }}

That being said, 2 decimal places, which is what you have specified here, IS the Angular default. You'd also get 2 decimal places with the following filter:

{{item.Price.Value | currency}}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to construct a Currency Locale from a String?

How to get the currency symbol from Locale Swift

From the locale, how do I get the currency code?

How to hide currency symbol in angular currency pipe

Angularjs: How to multiply total got from total filter in angularjs for showing total in different currency value?

how to make a currency search filter?

How do I format a Currency for a Locale in Java

How to determine if locale currency has a decimal point

How to set different currency in different cell depending on currency code

Currency format (by locale) in Dart

Currency Code to locale JS

How to modify the currency filter, according to my currency symbol, Angularjs

How to allow user to specify currency format in Swift

How to style angular ngBind currency

Angular Default Currency Pipe not working along with amount

How do I extract the Currency from "Total Currency" VBA /BDP

How to set the default currency of Laravel Cashier

Visual studio 2015 - How to change default currency?

How to change default currency in Crinsane/LaravelShoppingcart?

How to set default currency type in Libre office

How to filter data by matching currency code

How to filter a range of currency values in footable?

Not getting currency symbols for specific Locale

Java: Currency to Locale Mapping Possible?

How to get the currency symbol for particular country using locale?

How to get locale currency price for in-app purchases in iOS?

How to add support for all locale's currency symbols in a flutter app

Magento 2 How to customize Currency symbol and format based on locale

How to format Price / Currency text according to user locale in XML view?