import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'minimizeNumber'
})
export class MinimizeNumberPipe implements PipeTransform {

  transform(n: number): string {
    let units:string;
    let val:string;
    if(n<1000) {
      units = "";
      val = n.toString();
    }
    else if(n < 1000000) {
      units = "K";
      n = n/1000; 
    }
    else if(n < 1000000000) {
      units = "M";
      n = n/1000000; 
    }
    else {
      units = "B";
      n = n/1000000000; 
    }
    
    val = (Math.round(n*100)/100).toFixed(0);
    return `${val}${units}`;
  }

}
