How to change delimiter in Angularjs number filter from comma to something custom?
Now {{ price | number }}
returns 1,000.00
.
And I need to have it like 1 000.00
.
How exactly do I need to rewrite built-in angular filter?
You don't have to mess with Angular source or change locale to other. You don't even need to write custom filter for this. just change NUMBER_FORMATS.GROUP_SEP
of the $locale service to whatever you need:
$locale.NUMBER_FORMATS.GROUP_SEP = ' ';
$scope.price = 100000;
But it's better to do it in run block, rather then in controller.
angular.module('demo', []).controller('MainCtrl', function($scope, $locale) {
$locale.NUMBER_FORMATS.GROUP_SEP = ' ';
$scope.price = 100000;
});
<script src="https://code.angularjs.org/1.4.3/angular.js"></script>
<div ng-app="demo" ng-controller="MainCtrl">
{{ price | number }}
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With