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;
}
}
}
})
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;
}
}
}
})
Share
Improve this question
edited Dec 12, 2016 at 15:37
Diego
asked Dec 12, 2016 at 14:02
DiegoDiego
2421 gold badge2 silver badges14 bronze badges
2
- Google: "AngularJS filter" – CraigR8806 Commented Dec 12, 2016 at 14:03
- Thanks, I have seen this before, but I don't see how can I change it. – Diego Commented Dec 12, 2016 at 14:10
2 Answers
Reset to default 3You can do it by simply changing your Locale to match the European currency:
Import this library
<script src="https://cdnjs.cloudflare./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
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.