Skip to content

Instantly share code, notes, and snippets.

@bbrown
Created March 20, 2015 18:56
Show Gist options
  • Save bbrown/d5ea6567044f1bce7553 to your computer and use it in GitHub Desktop.
Save bbrown/d5ea6567044f1bce7553 to your computer and use it in GitHub Desktop.
Angular filter to replace parentheses with a negative and round big numbers
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