2

How to add other currency formats like euro to currency filter in AngularJS ?

<div ng-app>
    <p>
        <label>Enter Cost</label>
        <input type="text" ng-model="cost" />
    </p>

    <p> {{ cost | currency }} </p>
</div>
3
  • you can create your own filters in angular js. Commented Dec 2, 2015 at 21:52
  • the second parameter of the filter is the string representing the symbol to use. i.e. {{cost | currency : "€" }} Commented Dec 2, 2015 at 21:52
  • Did you try looking this up? It's written pretty blatantly in the documentation. Commented Dec 2, 2015 at 21:54

5 Answers 5

2

You could choose to create a custom filter for your currency of choice. However according to Angulars Documentation on the Currency Filter that you can simply provide the symbol, currency abbreviation, and decimal place formatters for your currency .

In HTML Template Binding :

{{ currency_expression | currency : symbol : fractionSize}}      

In JavaScript :

$filter('currency')(amount, symbol, fractionSize)
Sign up to request clarification or add additional context in comments.

Comments

1

You can pass in html entities after currency:. Here are a couple examples.

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

From the documentation, the format for this filter is

{{ currency_expression | currency : symbol : fractionSize}}

Comments

1
<div ng-app>
    <p>
        <label>Enter Cost</label>
        <input type="text" ng-model="cost" />
    </p>
    <!-- Change USD$ to the currency symbol you want -->
    <p> {{cost| currency:"USD$"}} </p>
</div>

Comments

1

As described in the documentation, simply add the currency symbol you want after the filter.

<p> {{ cost | currency : '€' }} </p>

Comments

1
// Setup the filter
app.filter('customCurrency', function() { 

  // Create the return function and set the required parameter name to **input**
  // setup optional parameters for the currency symbol and location (left or right of the amount)
  return function(input, symbol, place) {

    // Ensure that we are working with a number
    if(isNaN(input)) {
      return input;
    } else {

      // Check if optional parameters are passed, if not, use the defaults
      var symbol = symbol || '$';
      var place = place === undefined ? true : place;

      // Perform the operation to set the symbol in the right location
      if( place === true) {
        return symbol + input;
      } else {
        return input + symbol;
      }

    }
  }

Then pass whatever currency you need.

<ul class="list">
     <li>{{example1 | customCurrency}} - Default</li>
     <li>{{example1 | customCurrency:'€'}} - Custom Symbol</li>
     <li>{{example1 | customCurrency:'€':false}} - Custom Symbol and Custom Location</li>
</ul>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.