32 lines
759 B
TypeScript
32 lines
759 B
TypeScript
|
|
||
|
export class NumberUtils{
|
||
|
|
||
|
|
||
|
|
||
|
public static roundNumber(num: number):any {
|
||
|
console.log("Trying to round number: "+ num);
|
||
|
var roundNum = null;
|
||
|
if(num >= 1000000){
|
||
|
num=num/1000000;
|
||
|
num= Math.round(num);
|
||
|
roundNum = { "number": num, "size": "mi" };
|
||
|
}else if( num >= 10000){
|
||
|
num=num/1000;
|
||
|
num= Math.round(num);
|
||
|
roundNum = { "number": num, "size": "K" };
|
||
|
}else if (num >= 100) {
|
||
|
num=num/100;
|
||
|
num= Math.round(num);
|
||
|
num=num*100;
|
||
|
roundNum = { "number": num, "size": "" };
|
||
|
}else{
|
||
|
roundNum = { "number": num, "size": "" };
|
||
|
}
|
||
|
console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size);
|
||
|
return roundNum;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|