2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
export class NumberUtils{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static roundNumber(num: number):any {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("Trying to round number: "+ num);
|
2017-12-19 13:53:46 +01:00
|
|
|
var roundNum = null;
|
2018-10-04 20:33:16 +02:00
|
|
|
var initialNum = num;
|
2017-12-19 13:53:46 +01:00
|
|
|
if(num >= 1000000){
|
|
|
|
num=num/1000000;
|
|
|
|
num= Math.round(num);
|
2019-11-02 02:27:34 +01:00
|
|
|
roundNum = { "number": num, "size": "M", count: initialNum};
|
|
|
|
}else if( num >= 1000){
|
2017-12-19 13:53:46 +01:00
|
|
|
num=num/1000;
|
|
|
|
num= Math.round(num);
|
2018-10-04 20:33:16 +02:00
|
|
|
roundNum = { "number": num, "size": "K", count: initialNum};
|
2017-12-19 13:53:46 +01:00
|
|
|
}else if (num >= 100) {
|
|
|
|
num=num/100;
|
|
|
|
num= Math.round(num);
|
|
|
|
num=num*100;
|
2018-10-04 20:33:16 +02:00
|
|
|
roundNum = { "number": num, "size": "" , count: initialNum};
|
2017-12-19 13:53:46 +01:00
|
|
|
}else{
|
2018-10-04 20:33:16 +02:00
|
|
|
roundNum = { "number": num, "size": "" , count: initialNum};
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size);
|
2017-12-19 13:53:46 +01:00
|
|
|
return roundNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|