2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
export class NumberUtils{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static roundNumber(num: number):any {
|
|
|
|
console.log("Trying to round number: "+ num);
|
|
|
|
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);
|
2018-10-04 20:33:16 +02:00
|
|
|
roundNum = { "number": num, "size": "mi", count: initialNum};
|
2017-12-19 13:53:46 +01:00
|
|
|
}else if( num >= 10000){
|
|
|
|
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
|
|
|
}
|
|
|
|
console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size);
|
|
|
|
return roundNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|