Leonardo
Leonardo

Reputation: 9

Replacing dots and commas in AngularJS

How can I change the decimal that by default is 'dot' by a 'comma' in the filter of currency in AngularJS?

Example:

{{10000 | currency}} 10,000.00 ==> 10.000,00

Thanks!

Upvotes: 0

Views: 1220

Answers (1)

Yosvel Quintero
Yosvel Quintero

Reputation: 19070

Here is a working demo using a decorator, in the configuration block, to modify locale NUMBER_FORMATS properties DECIMAL_SEP and GROUP_SEP. It is called only one time and is valid for any filter that depends on it:

angular
    .module('App', [])
    .config(['$provide', function($provide) {
        $provide.decorator('$locale', ['$delegate', function($delegate) {
            $delegate.NUMBER_FORMATS.DECIMAL_SEP = ',';
            $delegate.NUMBER_FORMATS.GROUP_SEP = '.';
            return $delegate;
        }]);
    }])
    .controller('ExampleController', function($scope) {
        $scope.myNumber = 10000;
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="App" ng-controller="ExampleController">
  <p>{{myNumber | currency}}</p>
</div>

Upvotes: 1

Related Questions