Created
March 20, 2015 18:56
-
-
Save bbrown/d5ea6567044f1bce7553 to your computer and use it in GitHub Desktop.
Angular filter to replace parentheses with a negative and round big numbers
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("app").filter("customCurrency", ["$filter", function($filter) | |
{ | |
return function(amount, currencySymbol, fractionSize) | |
{ | |
var currency = $filter("currency"); | |
if (Math.abs(amount) > 1000) | |
{ | |
fractionSize = 0; | |
amount = Math.round(amount); | |
} | |
if (amount && amount < 0) | |
{ | |
return currency(amount, currencySymbol, fractionSize).replace("(", "-").replace(")", ""); | |
} | |
return currency(amount, currencySymbol, fractionSize); | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment