Created
May 7, 2013 17:40
-
-
Save alfielapeter/5534530 to your computer and use it in GitHub Desktop.
Angular.js and Accounting.js Currency Filter
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
// 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