Last active
August 29, 2015 14:03
-
-
Save jordanburke/4fac254323b830889453 to your computer and use it in GitHub Desktop.
Angular Large Number Format
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
(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