Getting a currency format pattern from AngularJS filter

大兔子大兔子 提交于 2019-11-30 14:44:44

问题


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:


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.



来源:https://stackoverflow.com/questions/18745452/getting-a-currency-format-pattern-from-angularjs-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!