1 import { Pipe, PipeTransform } from '@angular/core'
3 // Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
5 @Pipe({ name: 'myNumberFormatter' })
6 export class NumberFormatterPipe implements PipeTransform {
7 private dictionary: Array<{max: number, type: string}> = [
8 { max: 1000, type: '' },
9 { max: 1000000, type: 'K' },
10 { max: 1000000000, type: 'M' }
13 transform (value: number) {
14 const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1]
15 const calc = Math.floor(value / (format.max / 1000))
17 return `${calc}${format.type}`