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?
AngularJS currency Filter The currency filter formats a number to a currency format. By default, the locale currency format is used.
AngularJS Filters AngularJS provides filters to transform data: currency Format a number to a currency format.
AngularJS Currency Filter Syntax E.g Suppose if we give expression like {{1000 | currency}} by default it will format our number and return result like $1,000.00.
In AngularJS, you can also inject the $filter service within the controller and can use it with the following syntax for the filter. Syntax: $filter("filter")(array, expression, compare, propertyKey) function myCtrl($scope, $filter) { $scope. finalResult = $filter("filter")( $scope.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With