Skip to content

Instantly share code, notes, and snippets.

@givp
Created January 5, 2016 05:18
Show Gist options
  • Save givp/1ee88d88fc4ac2019889 to your computer and use it in GitHub Desktop.
Save givp/1ee88d88fc4ac2019889 to your computer and use it in GitHub Desktop.
Angular 1.x number abbreviation filter
// Usage in template: My number is {{ value|abbnumber }}
myApp.filter('abbnumber', function() {
return function(input) {
input = parseInt(input);
if (input >= 10000000) {
return (input / 1000000).toFixed(0) + 'M'
}
if (input >= 1000000) {
return (input / 1000000).toFixed(1) + 'M'
}
if (input >= 10000) {
return (input / 1000).toFixed(0) + 'K'
}
if (input >= 1000) {
return (input / 1000).toFixed(1) + 'K'
}
return input;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment