Last active
June 14, 2016 01:12
-
-
Save yahyaKacem/541c0ee70d01586d751f235ef52ad557 to your computer and use it in GitHub Desktop.
Revisions
-
yahyaKacem revised this gist
Jun 14, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // based on https://gist.github.com/maggiben/9457434 import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'humanize'}) -
yahyaKacem created this gist
Jun 14, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'humanize'}) export class Humanize implements PipeTransform { transform(value: number): any { let si: string[], exp: number, result: any; if (value < 1000) { return value; } si = ['K', 'M', 'G', 'T', 'P', 'H']; exp = Math.floor(Math.log(value) / Math.log(1000)); result = value / Math.pow(1000, exp); result = (result % 1 > (1 / Math.pow(1000, exp - 1))) ? result.toFixed(2) : result.toFixed(0); return result + si[exp - 1]; } }