2021-04-16 20:18:02 +02:00
|
|
|
export interface NumberSize {
|
|
|
|
number: number;
|
2022-12-21 12:37:16 +01:00
|
|
|
size: "B" | "M" | "K" | "";
|
2021-04-16 20:18:02 +02:00
|
|
|
count: number;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
export class NumberUtils{
|
2021-04-16 20:18:02 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
public static roundNumber(num: number):any {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("Trying to round number: "+ num);
|
2021-04-16 20:18:02 +02:00
|
|
|
var roundNum: NumberSize = null;
|
2018-10-04 20:33:16 +02:00
|
|
|
var initialNum = num;
|
2022-12-21 12:37:16 +01:00
|
|
|
if (num >= 1000000000) {
|
|
|
|
num = num / 1000000;
|
|
|
|
num = Math.round(num);
|
|
|
|
roundNum = {number: num, size: "B", count: initialNum};
|
|
|
|
} else if(num >= 1000000) {
|
2017-12-19 13:53:46 +01:00
|
|
|
num=num/1000000;
|
|
|
|
num= Math.round(num);
|
2021-04-16 20:18:02 +02:00
|
|
|
roundNum = { number: num, size: "M", count: initialNum};
|
2019-11-02 02:27:34 +01:00
|
|
|
}else if( num >= 1000){
|
2017-12-19 13:53:46 +01:00
|
|
|
num=num/1000;
|
|
|
|
num= Math.round(num);
|
2021-04-16 20:18:02 +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;
|
2021-04-16 20:18:02 +02:00
|
|
|
roundNum = { number: num, size: "" , count: initialNum};
|
2017-12-19 13:53:46 +01:00
|
|
|
}else{
|
2021-04-16 20:18:02 +02:00
|
|
|
roundNum = { number: num, size: "" , count: initialNum};
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
return roundNum;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|