Skip to content

Instantly share code, notes, and snippets.

@hughes
Created May 25, 2014 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughes/bfe7afbfe968ce803613 to your computer and use it in GitHub Desktop.
Save hughes/bfe7afbfe968ce803613 to your computer and use it in GitHub Desktop.
angular filters for currency formatting
angular.module("filters", [])
.filter('round', function () {
return function (input, precision) {
return input ? parseFloat(input).toFixed(precision) : "";
};
})
.filter('dollars', function () {
return function (input) {
return input ? '$' + input : ''
};
})
.filter('commas', function () {
return function (input) {
return input ? input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : '';
}
})
@hughes
Copy link
Author

hughes commented May 25, 2014

Usage: {{ value | round:2 | commas | dollars }}

@hughes
Copy link
Author

hughes commented Jun 10, 2014

or even better, use the built-in currency filter... duh!

{{ value | currency }}

._.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment