Created
January 5, 2016 05:18
-
-
Save givp/1ee88d88fc4ac2019889 to your computer and use it in GitHub Desktop.
Angular 1.x number abbreviation filter
This file contains hidden or 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
// 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