jQuery 如何在 angular js 中获取特定的货币符号(在我的例子中是卢比符号)而不是默认的货币符号(美元符号)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18612212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 22:02:43  来源:igfitidea点击:

How to get specific currency symbol(rupee symbol in my case) in angular js instead of the default one (dollar $ symbol)

javascriptjqueryhtmlangularjs

提问by Ebenezar John Paul

When i use 'currency' in angular js, I am getting a dollar symbol. How to get required currency symbols based on the requirements. As if now i need to know how to display a rupee symbol using currency. It will be of great use if anyone could explain how to make use of this currency for different symbols at the times of different requirements.

当我在 angular js 中使用“货币”时,我得到了一个美元符号。如何根据要求获取所需的货币符号。好像现在我需要知道如何使用货币显示卢比符号。如果有人可以解释如何在不同要求的时候将这种货币用于不同的符号,那将非常有用。

sample :

样本 :

Item Price<span style="font-weight:bold;">{{item.price | currency}}</span>

If my item.price is 200. Here it shows 200$. I need to display rupee symbol instead of dollar.

如果我的 item.price 是 200。这里显示 200$。我需要显示卢比符号而不是美元。

回答by JQuery Guru

To display currency symbol in angular js you need provide HTML entity for currency symbols below are the examples and usage in through code and in template :

要在 angular js 中显示货币符号,您需要为货币符号提供 HTML 实体,下面是直通代码和模板中的示例和用法:

Inside your Template example of Euro:

在您的欧元模板示例中:

Item Price<span style="font-weight:bold;">{{price | currency:"&euro;"}}</span>

example of Rupee:

卢比的例子:

Item Price<span style="font-weight:bold;">{{price | currency:"&#8377;"}}</span>

Also check below url

还要检查下面的网址

http://www.cs.tut.fi/~jkorpela/html/euro.html

http://www.cs.tut.fi/~jkorpela/html/euro.html

From controller :

从控制器:

Inject $filter in your controller

在控制器中注入 $filter

$scope.price=$filter('currency')($scope.price,'&euro;')

回答by Scalpweb

You can use the symbol parameter:

您可以使用符号参数:

Item Price<span style="font-weight:bold;">{{item.price | currency[:symbol]}}</span>

Exemple:

例子:

Item Price<span style="font-weight:bold;">{{item.price | currency:"USD$"}}</span>

Please refer to this:

请参考这个:

http://docs.angularjs.org/api/ng.filter:currency

回答by zwacky

I'm late to the party but worked on this filter for my last project.

我参加聚会迟到了,但为我的上一个项目使用了这个过滤器。

if you have the ISO 4217 currency code (3 chars length e.g. USD, EUR, etc) isoCurrency can output the right format, fraction sizeand symbol.

如果您有 ISO 4217 货币代码(3 个字符长度,例如 USD、EUR 等),isoCurrency 可以输出正确的格式分数大小符号

// in controller
$scope.amount = 50.50;
$scope.currency = 'USD';

// in template
{{ amount | isoCurrency:currency }} // .50

回答by mahesh

Simple solution giving for the INR currency.

提供 INR 货币的简单解决方案。

If you want to display symbol

如果要显示符号

Item Price<span style="font-weight:bold;">{{item.price | currency:'INR'}}</span>

or

或者

Item Price<span style="font-weight:bold;">{{item.price | currency:'INR':'symbol'}}</span>

or

或者

Item Price<span style="font-weight:bold;">{{item.price | currency:'INR':'symbol-narrow'}}</span>

Result will look like: ?140.00

结果看起来像:?140.00

Or If you want to display codeinstead of symbol then use following

或者,如果您想显示代码而不是符号,请使用以下内容

 Item Price<span style="font-weight:bold;">{{item.price | currency:'INR':'code'}}</span>

Result will look like : INR140.00

结果看起来像:INR140.00

Similarly you can check for the code of the other countries and replace that instead of INR(India Code)

同样,您可以检查其他国家/地区的代码并将其替换为 INR(印度代码)

回答by Foreever

The currency symbol can be changed from the default $ symbol to something else as follows:
In HTML Template Binding

货币符号可以从默认的 $ 符号更改为其他内容,如下所示:
在 HTML 模板绑定中

 {{ currency_expression | currency[:symbol] }} 

In JavaScript

在 JavaScript 中

 $filter('currency')(amount[, symbol]) 

We can display rupee symbol(in this case) for example as follows:
In HTML Template Binding

我们可以显示卢比符号(在这种情况下),例如:
在 HTML 模板绑定中

Item Price<span style="font-weight:bold;">{{price | currency:"&#8377;"}}</span> 

OR

或者

In JavaScript

在 JavaScript 中

$scope.price=$filter('currency')($scope.price,"&#8377;")

Also, we can add a text rather than a symbol if needed as follows:

此外,如果需要,我们可以添加文本而不是符号,如下所示:

Item Price<span style="font-weight:bold;">{{price | currency:"rupee"}}</span> 

Note: Copying rupee symbol directly into HTML will not work.

注意:将卢比符号直接复制到 HTML 中是行不通的。

See AngularJS currency documentation

请参阅AngularJS 货币文档

回答by Naresh

<h2>{{8.99 | currency:'INR':true}}</h2>

回答by Alon

if you want to make it dynamic, here is my solution:

如果你想让它动态,这是我的解决方案:

HTML

HTML

<div>{{ 100 | currencySymbol: 'USD' }}</div>

Filter

筛选

angular.filter('currencySymbol', function ($filter) {
    return function(amount, currency) {
        return $filter('currency')(amount, currency_symbols[currency]);
    }
});

Javascript currency array

Javascript 货币数组

var currency_symbols = {
    'USD': '$', // US Dollar
    'EUR': '', // Euro
    'GBP': '£', // British Pound Sterling
    'ILS': '?', // Israeli New Sheqel
    'INR': '?', // Indian Rupee
    'JPY': '¥', // Japanese Yen
    'KRW': '?', // South Korean Won
    'NGN': '?', // Nigerian Naira
    'PHP': '?', // Philippine Peso
    'PLN': 'z?', // Polish Zloty
    'PYG': '?', // Paraguayan Guarani
    'THB': '?', // Thai Baht
    'UAH': '?', // Ukrainian Hryvnia
    'VND': '?', // Vietnamese Dong
};

回答by Rajat Garg

$ is the default symbol for angular currency filter. To get the result in other symbol, for example Rupee (?), you must explicitly define it in your app. For displaying ₹ symbol you just have to add an option in currency.

$ 是角度货币过滤器的默认符号。要在其他符号中获得结果,例如卢比 (?),您必须在您的应用程序中明确定义它。要显示 ₹ 符号,您只需添加一个货币选项。

Example:

例子:

<span> <b>{{i.price | currency : '&#8377;' }}</b> </span>

<span> <b>{{i.price | currency : '&#8377;' }}</b> </span>

&#8377;is the HTML code for ₹ symbol.

&#8377;是 ₹ 符号的 HTML 代码。

回答by gdmanandamohon

According to Angular JS docs Linkthe currency can be changed

根据 Angular JS docs Link可以更改货币

Item Price<span style="font-weight:bold;">{{price | currency:[symbol]}}</span>
Item Price in Dollar<span style="font-weight:bold;">{{price | currency:"USD$"}}</span>
Item Price in Euro<span style="font-weight:bold;">{{price | currency:"&euro;"}}</span>

And for INR it will be character code Link2

对于 INR,它将是字符代码Link2

Item Price in Ruppese<span style="font-weight:bold;">{{price | currency:"&#8377;"}}</span>

"&#8377;"is the character code of :"₹"

"&#8377;"是字符代码:“$”

回答by tea2code

See: http://docs.angularjs.org/api/ng.filter:currency

请参阅:http: //docs.angularjs.org/api/ng.filter: currency

Simple with:

简单:

currency:"USD$"

and instead of USD$ use what ever you want

而不是美元$使用你想要的任何东西