Project

General

Profile

1

    
2
export class NumberUtils{
3

    
4

    
5

    
6
  public static roundNumber(num: number):any {
7
      //console.log("Trying to round number: "+ num);
8
      var roundNum = null;
9
      var initialNum = num;
10
      if(num >= 1000000){
11
        num=num/1000000;
12
        num= Math.round(num);
13
        roundNum =  { "number": num, "size": "M", count: initialNum};
14
      }else if( num >= 1000){
15
        num=num/1000;
16
        num= Math.round(num);
17
        roundNum =  { "number": num, "size": "K", count: initialNum};
18
      }else if (num >= 100) {
19
        num=num/100;
20
        num= Math.round(num);
21
        num=num*100;
22
        roundNum =  { "number": num, "size": "" , count: initialNum};
23
      }else{
24
        roundNum =  { "number": num, "size": "" , count: initialNum};
25
      }
26
      //console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size);
27
      return roundNum;
28
  }
29

    
30

    
31

    
32
}
(14-14/22)