从 AngularJS 过滤器获取货币格式模式 [英] Getting a currency format pattern from AngularJS filter

查看:13
本文介绍了从 AngularJS 过滤器获取货币格式模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣创建一个可以接受金额、ISO 4217 货币代码和分数大小并以该格式返回金额的过滤器.我注意到 AngularJS 在 i18n/closure/currencySymbols.js 中有 goog.i18n.currency.getGlobalCurrencyPattern,但我对 Angular 比较陌生,不确定是否可行使用它?

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.

就使用内置货币格式而言,有多种方式:在模板中,在代码中.

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

在模板中:

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

在代码中:

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 代码示例:http://jsfiddle.net/TheSharpieOne/N7YuP/3/

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

注意:ISO 4217 没有规定货币符号,我使用 this 作为符号参考并映射它们.

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

这篇关于从 AngularJS 过滤器获取货币格式模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆