I am following this: http://docs.angularjs.org/api/ng.filter:currency When I type 1234.56 in the field then the output should be $1,234.56. But if I type in the input 1234 then
Add a new filter:
'use strict';
angular
.module('myApp')
.filter('myCurrency', ['$filter', function($filter) {
return function(input) {
input = parseFloat(input);
input = input.toFixed(input % 1 === 0 ? 0 : 2);
return '$' + input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};
}]);
In your view:
{{ '100' | myCurrency }}
{{ '100.05' | myCurrency }}
{{ '1000' | myCurrency }}
{{ '1000.05' | myCurrency }}