充分利用AngularJS过滤货币格式模式 [英] Getting a currency format pattern from AngularJS filter
问题描述
我感兴趣的是建立一个过滤器,将接受量,ISO 4217货币code和分数的大小,并在格式返回的金额。我注意到,AngularJS具有 goog.i18n.currency.getGlobalCurrencyPattern
在国际化/关闭/ currencySymbols.js
,但我米比较新的角度和不知道是否可以使用它?
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?
推荐答案
货币图案和符号是正义的。它确定如何显示的数字。它不会从XXX其转换为XXX。你将有基于当前的转换率做转换部分
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.
至于使用内置的货币格式,有多种方法:在模板中,code
As far as using the built-in currency formatting, there are multiple ways: in the template, in the code.
在模板:
<div>{{myCurrencyValue | currency:'XXX'}}</div>
在code:
var formatted = $filter('currency')(myCurrencyValue, 'XXX')
在这两种情况下,'XXX'
是可选[和符号是],将使用默认的货币当前的区域
In both cases, 'XXX'
is optional [and is symbol] and will use the default currency for current locale
例如: http://jsfiddle.net/TheSharpieOne/N7YuP/
更多信息可以在这里找到:货币文档
More information can be found here: Currency Docs
更新
使用自定义过滤器ISO 4217 codeS例如: http://jsfiddle.net/TheSharpieOne/N7YuP/3/
Example with ISO 4217 codes using custom filter: http://jsfiddle.net/TheSharpieOne/N7YuP/3/
请注意:4217没有规定的货币符号,我用这符号参考,并映射到它们
Note: ISO 4217 doesn't dictate the currency symbols, I used this for symbol reference and mapped them.
这篇关于充分利用AngularJS过滤货币格式模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!