33 lines
861 B
TypeScript
33 lines
861 B
TypeScript
|
|
export class NumberUtils{
|
|
|
|
|
|
|
|
public static roundNumber(num: number):any {
|
|
console.log("Trying to round number: "+ num);
|
|
var roundNum = null;
|
|
var initialNum = num;
|
|
if(num >= 1000000){
|
|
num=num/1000000;
|
|
num= Math.round(num);
|
|
roundNum = { "number": num, "size": "mi", count: initialNum};
|
|
}else if( num >= 10000){
|
|
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};
|
|
}
|
|
console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size);
|
|
return roundNum;
|
|
}
|
|
|
|
|
|
|
|
}
|