Created
May 25, 2014 19:12
-
-
Save hughes/bfe7afbfe968ce803613 to your computer and use it in GitHub Desktop.
angular filters for currency formatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ",") : ''; | |
} | |
}) |
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
Usage:
{{ value | round:2 | commas | dollars }}