2

I have this number.

20.79

I need see the number as

20,79

Or

1.200,76 €

How can I change the . by , and add € currency?

Thanks!

Solution

app.filter('customCurrency', function(){
    return function(input, symbol, place){
        if(isNaN(input)){
            return input;
        } else {
            var symbol = symbol || '$';
            var place = place === undefined ? true : place;
            if(place === true){
                return symbol + input;
            } else{
                var new_input = input.replace(".", ",");
                return new_input + symbol;
            }
        }
    }
})
2
  • Google: "AngularJS filter" Commented Dec 12, 2016 at 14:03
  • Thanks, I have seen this before, but I don't see how can I change it. Commented Dec 12, 2016 at 14:10

2 Answers 2

3

You can do it by simply changing your Locale to match the European currency:

Import this library

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.6.0/angular-locale_de-de.js"></script>

In your html

<div>{{ myNumber | currency: '€' }}</div>

In your controller

$scope.myNumber = 1220.79;

Result: 1.220,79 €

Please check it: JSFiddle Demo

Sign up to request clarification or add additional context in comments.

Comments

2

Use the currency filter:

In your Angular controller:

$scope.myNumber = 20.79;

In your HTML page:

<div>{{myNumber | currency}}</div>

Update: If you need to display in €, 2 options:

  • Set your locale to your country: <script src="i18n/angular-locale_de-de.js"></script> (best option).
  • Display it without currency filter: {{(myNumber | number: 2) + " €"}}.

Demo on JSFiddle.

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.