13

I'm interested in creating a filter that would accept an amount, ISO 4217 currency code, and fraction size, and return the amount in that format. I noticed that AngularJS has goog.i18n.currency.getGlobalCurrencyPattern in i18n/closure/currencySymbols.js, but I'm relatively new to Angular and not sure if it is possible to use it?

1 Answer 1

19

The currency pattern and symbols are just that. It determines how to display a number. It will not convert it from XXX to XXX. You will have to do the converting part based on the current conversion rates.

As far as using the built-in currency formatting, there are multiple ways: in the template, in the code.

In the template:

<div>{{myCurrencyValue | currency:'XXX'}}</div>

In the code:

var formatted = $filter('currency')(myCurrencyValue, 'XXX')

In both cases, 'XXX' is optional [and is symbol] and will use the default currency for current locale

Example: http://jsfiddle.net/TheSharpieOne/N7YuP/

More information can be found here: Currency Docs

UPDATE

Example with ISO 4217 codes using custom filter: http://jsfiddle.net/TheSharpieOne/N7YuP/3/

Note: ISO 4217 doesn't dictate the currency symbols, I used this for symbol reference and mapped them.

Sign up to request clarification or add additional context in comments.

8 Comments

My understanding is that the existing option on the currency filter is for a different currency symbol. I would really like to take a number, ISO 4217 Currency Code, and fraction size and have it formatted. For example: var formattedValue = $filter('myfilter')(1000, 'EUR', 2);
Your better off creating a filter and utilizing JS that has already been made like money.js which will also do conversion for you. If you would like I will change my answer to create a new filter using this.
I went ahead and updated it using a custom filter to use the ISO codes. I had to custom map the ISO codes to the symbols. You can see that mapping the in fiddle. I am also using accounting.js for formatting.
Thanks for helping and your quick solution! The thing is that I don't really want to maintain the formatting rules. I'm concerned about variations in thousands separators, decimal separators, negative numbers, etc. That is why I am interested in the goog.i18n.currency library.
@SajidAli It appears that when I generated the formatting map (from xe.com/symbols.php) INR didn't come through, if you look it is "INR": {"text":"","uniDec":"","uniHex":""}. I looked at xe.com/symbols.php and the information for INR is blank there. If you know the missing information (symbol, uniDec, uniHex) it can be added and it would work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.