diff --git a/utils/number-utils.class.ts b/utils/number-utils.class.ts
index 61054a75..4e17cfb1 100644
--- a/utils/number-utils.class.ts
+++ b/utils/number-utils.class.ts
@@ -1,5 +1,5 @@
export enum Level {
- NONE,
+ ALL,
K,
M,
B
@@ -14,7 +14,8 @@ export interface NumberSize {
export class NumberUtils {
- public static roundNumber(num: number, level: Level = Level.NONE, decimal = 0): any {
+ public static roundNumber(num: number | string, level: Level = Level.ALL, decimal = 0): any {
+ num = Number.parseFloat(num.toString());
let roundNum: NumberSize;
let initialNum = num;
let variance = Math.pow(10, decimal);
@@ -30,11 +31,6 @@ export class NumberUtils {
num = num / 1000;
num = Math.round(num * variance) / variance;
roundNum = {number: num, size: "K", count: initialNum};
- } else if (num >= 100) {
- num = num / 100;
- num = Math.round(num * variance) / variance;
- num = num * 100;
- roundNum = {number: num, size: "", count: initialNum};
} else {
roundNum = {number: num, size: "", count: initialNum};
}
diff --git a/utils/pipes/number-round.pipe.ts b/utils/pipes/number-round.pipe.ts
index 62608761..b42a93aa 100644
--- a/utils/pipes/number-round.pipe.ts
+++ b/utils/pipes/number-round.pipe.ts
@@ -5,19 +5,24 @@ import {DecimalPipe} from "@angular/common";
@Pipe({name: 'numberRound'})
export class NumberRoundPipe implements PipeTransform {
decimalPipe: DecimalPipe = new DecimalPipe("en");
-
- constructor() {}
-
- transform(value: number, ...args: any[]): any {
- let level = Level.NONE;
+
+ constructor() {
+ }
+
+ /**
+ * Args: Level: 0 (default): ALL, 1: K, 2: M, 3:B
+ * Decimal: how many decimals should be shown (e.g 1 -> 62.1)
+ * */
+ transform(value: number | string, ...args: any[]): any {
+ let level = Level.ALL;
let decimal = 0;
- if(args[0]) {
+ if (args[0]) {
level = args[0];
}
- if(args[1]) {
+ if (args[1]) {
decimal = args[1];
}
let size: NumberSize = NumberUtils.roundNumber(value, level, decimal);
- return this.decimalPipe.transform(size.number) + (size.size?'' + size.size + '':'');
+ return this.decimalPipe.transform(size.number) + (size.size ? '' + size.size + '' : '');
}
}