Revision 60895
Added by Konstantinos Triantafyllou almost 3 years ago
number-utils.class.ts | ||
---|---|---|
1 |
export interface NumberSize { |
|
2 |
number: number; |
|
3 |
size: "M" | "K" | ""; |
|
4 |
count: number; |
|
5 |
} |
|
1 | 6 |
|
2 | 7 |
export class NumberUtils{ |
3 |
|
|
4 |
|
|
5 |
|
|
8 |
|
|
6 | 9 |
public static roundNumber(num: number):any { |
7 | 10 |
//console.log("Trying to round number: "+ num); |
8 |
var roundNum = null; |
|
11 |
var roundNum: NumberSize = null;
|
|
9 | 12 |
var initialNum = num; |
10 | 13 |
if(num >= 1000000){ |
11 | 14 |
num=num/1000000; |
12 | 15 |
num= Math.round(num); |
13 |
roundNum = { "number": num, "size": "M", count: initialNum};
|
|
16 |
roundNum = { number: num, size: "M", count: initialNum};
|
|
14 | 17 |
}else if( num >= 1000){ |
15 | 18 |
num=num/1000; |
16 | 19 |
num= Math.round(num); |
17 |
roundNum = { "number": num, "size": "K", count: initialNum};
|
|
20 |
roundNum = { number: num, size: "K", count: initialNum};
|
|
18 | 21 |
}else if (num >= 100) { |
19 | 22 |
num=num/100; |
20 | 23 |
num= Math.round(num); |
21 | 24 |
num=num*100; |
22 |
roundNum = { "number": num, "size": "" , count: initialNum};
|
|
25 |
roundNum = { number: num, size: "" , count: initialNum};
|
|
23 | 26 |
}else{ |
24 |
roundNum = { "number": num, "size": "" , count: initialNum};
|
|
27 |
roundNum = { number: num, size: "" , count: initialNum};
|
|
25 | 28 |
} |
26 |
//console.log("Rounded number: "+ roundNum.number + " "+ roundNum.size); |
|
27 | 29 |
return roundNum; |
28 | 30 |
} |
29 | 31 |
|
Also available in: Unified diff
[Library | Trunk]: Numbers: Add init function. Create numberSize interface