Skip to content

Instantly share code, notes, and snippets.

@jordanburke
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordanburke/4fac254323b830889453 to your computer and use it in GitHub Desktop.
Save jordanburke/4fac254323b830889453 to your computer and use it in GitHub Desktop.
Angular Large Number Format
(function() {
this.app = angular.module('myApp', []);
this.app.filter("largeNumberFormat", function() {
return function(number) {
var abs;
if (number !== void 0) {
console.log(number);
abs = Math.abs(number);
if (abs >= Math.pow(10, 12)) {
number = (number / Math.pow(10, 12)).toFixed(1) + "T";
} else if (abs < Math.pow(10, 12) && abs >= Math.pow(10, 9)) {
number = (number / Math.pow(10, 9)).toFixed(1) + "B";
} else if (abs < Math.pow(10, 9) && abs >= Math.pow(10, 6)) {
number = (number / Math.pow(10, 6)).toFixed(1) + "M";
} else if (abs < Math.pow(10, 6) && abs >= Math.pow(10, 3)) {
number = (number / Math.pow(10, 3)).toFixed(1) + "K";
}
return number;
}
};
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment