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
?
5 Answers
Reset to default 31.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:"€" }}</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);