Skip to content

Instantly share code, notes, and snippets.

View yahyaKacem's full-sized avatar

Yahya Kacem yahyaKacem

View GitHub Profile
@yahyaKacem
yahyaKacem / humanize.js
Last active June 14, 2016 01:06 — forked from maggiben/humanize.js
Human Readable Numbers (AngularJS filter)
angular.module('humanize', []).filter('humanize', function() {
return function humanize(number) {
var si, exp, result;
if (number < 1000) {
return number;
}
si = ['K', 'M', 'G', 'T', 'P', 'H'];
exp = Math.floor(Math.log(number) / Math.log(1000));
result = number / Math.pow(1000, exp);
result = (result % 1 > (1 / Math.pow(1000, exp - 1))) ? result.toFixed(2) : result.toFixed(0);