Project

General

Profile

1 50169 argiro.kok
2
export class NumberUtils{
3
4
5
6
  public static roundNumber(num: number):any {
7 54775 konstantin
      //console.log("Trying to round number: "+ num);
8 50169 argiro.kok
      var roundNum = null;
9 53392 argiro.kok
      var initialNum = num;
10 50169 argiro.kok
      if(num >= 1000000){
11
        num=num/1000000;
12
        num= Math.round(num);
13 57499 konstantin
        roundNum =  { "number": num, "size": "M", count: initialNum};
14
      }else if( num >= 1000){
15 50169 argiro.kok
        num=num/1000;
16
        num= Math.round(num);
17 53392 argiro.kok
        roundNum =  { "number": num, "size": "K", count: initialNum};
18 50169 argiro.kok
      }else if (num >= 100) {
19
        num=num/100;
20
        num= Math.round(num);
21
        num=num*100;
22 53392 argiro.kok
        roundNum =  { "number": num, "size": "" , count: initialNum};
23 50169 argiro.kok
      }else{
24 53392 argiro.kok
        roundNum =  { "number": num, "size": "" , count: initialNum};
25 50169 argiro.kok
      }
26 54775 konstantin
      //console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size);
27 50169 argiro.kok
      return roundNum;
28
  }
29
30
31
32
}