Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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