openaire-library/utils/number-utils.class.ts

35 lines
871 B
TypeScript

export interface NumberSize {
number: number;
size: "M" | "K" | "";
count: number;
}
export class NumberUtils{
public static roundNumber(num: number):any {
//console.log("Trying to round number: "+ num);
var roundNum: NumberSize = null;
var initialNum = num;
if(num >= 1000000){
num=num/1000000;
num= Math.round(num);
roundNum = { number: num, size: "M", count: initialNum};
}else if( num >= 1000){
num=num/1000;
num= Math.round(num);
roundNum = { number: num, size: "K", count: initialNum};
}else if (num >= 100) {
num=num/100;
num= Math.round(num);
num=num*100;
roundNum = { number: num, size: "" , count: initialNum};
}else{
roundNum = { number: num, size: "" , count: initialNum};
}
return roundNum;
}
}