FM.Du FM.Du - 1 month ago 12
AngularJS Question

angularjs currency filter add extra plus symbol in front

I'm using the filter the following way in html.

var mydata = 20000;

{{mydata | currency : '$' : 2}}


however, the value shows as +20,000.00
It has one extra "+" for the value.

Is there a way to remove that?

Thanks!

zee zee
Answer

Check to make sure that you're not overwriting the default currency symbol somewhere in your code. See the following example.

script.js

var app = angular.module('root', []);

app.run(["$locale", function ($locale) {
  $locale.NUMBER_FORMATS.CURRENCY_SYM = "+"
}]);

app.component('root', {
  template: `
  <div>
    <!-- Prints out $20,000 -->
    {{ $ctrl.myData | currency: "$": 2 }}
  </div>
  <div>
    <!-- Prints out +20,000 -->
    {{ $ctrl.myDataPlus | currency }}
  </div>
  `,
  controller: function() {
    this.myData = "20000";
    this.myDataPlus = "20000";
  }
});

index.html

<html ng-app="root">
  <head>
    <script data-require="angular.js@*" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular.js"></script>
    <script src="script.js"></script>
  </head>

  <body>
    <root></root>
  </body>

</html>