Skip to content

Instantly share code, notes, and snippets.

@alfielapeter
Created May 7, 2013 17:40
Show Gist options
  • Save alfielapeter/5534530 to your computer and use it in GitHub Desktop.
Save alfielapeter/5534530 to your computer and use it in GitHub Desktop.
Angular.js and Accounting.js Currency Filter
// sample use {{ value | currency:"USD" }}
angular.module('filters', []).filter('currency', function() {
return function(number, currencyCode) {
var currency = {
USD: "$",
GBP: "£",
AUD: "$",
EUR: "€",
CAD: "$",
MIXED: "~"
},
thousand, decimal, format;
if ($.inArray(currencyCode, ["USD", "AUD", "CAD", "MIXED"]) >= 0) {
thousand = ",";
decimal = ".";
format = "%s%v";
} else {
thousand = ".";
decimal = ",";
format = "%s%v";
};
return accounting.formatMoney(number, currency[currencyCode], 2, thousand, decimal, format);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment