最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to customize the currency filter to display the currency symbol '€' or any other in angularJS -

programmeradmin0浏览0评论

The default currency symbol in the currency filter in angularJS is $. how can I change that to '€' or any other ? I found some lengthy codes in here. But is there any smooth way to do it ?

<div ng-app=""  >

    <p>Total = {{ (10 * 13) | currency }}</p>

</div>

result is Total = $130.00 how to make it Total = €130.00 or Total = USD130.00 ?

The default currency symbol in the currency filter in angularJS is $. how can I change that to '€' or any other ? I found some lengthy codes in here. But is there any smooth way to do it ?

<div ng-app=""  >

    <p>Total = {{ (10 * 13) | currency }}</p>

</div>

result is Total = $130.00 how to make it Total = €130.00 or Total = USD130.00 ?

Share Improve this question edited Oct 15, 2018 at 16:38 Cœur 38.8k25 gold badges206 silver badges278 bronze badges asked May 25, 2015 at 8:26 primeprime 15.6k16 gold badges104 silver badges137 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 3

1.Try this {{price | currency:"€"}} , It will solve your problem http://jsfiddle/TheSharpieOne/N7YuP/

2.And To make in more generalized format, it would be better if you can write custom filter for currency formats.

So that it can support any of the currency formats.

Example

As per the documentation, you can specify a custom currency identifier

{{amount | currency:"€"}}

Angular also provides handling for i18n/l10n

You can supply a currency symbol to the filter:

<script src="https://ajax.googleapis./ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app=""  >

    <p>Total = {{ (10 * 13) | currency : '€' }}</p>

</div>

All you have to do is provide a symbol parameter to the currency filter. The Angular docs provides the following syntax:

{{ currency_expression | currency : symbol : fractionSize}}

The correct symbol can be found by searching on the internet. But since you asked for Euro, here are a few variations:

<div ng-app=""  >

    <p>Total = {{ (10 * 13) | currency:"&euro;" }}</p>

</div>

OR

<div ng-app=""  >

    <p>Total = {{ (10 * 13) | currency:"€" }}</p>

</div>

Note: the symbol parameter must be a string

Alternatively you can even use the filter in controllers or custom filters by using the JavaScript syntax provided in the docs Angular API:currency -

For eg: $filter('currency')(input,"€"); or $filter('currency')(input,"€");

Note: Do remember to inject $filter into the controller or custom filter in question.

Hope that helps!

$filter('currency')(value, currencySymbol, fraction);

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论