Merge from Develop for Monitor production release #3
|
@ -1,5 +1,5 @@
|
||||||
export enum Level {
|
export enum Level {
|
||||||
NONE,
|
ALL,
|
||||||
K,
|
K,
|
||||||
M,
|
M,
|
||||||
B
|
B
|
||||||
|
@ -14,7 +14,8 @@ export interface NumberSize {
|
||||||
|
|
||||||
export class NumberUtils {
|
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 roundNum: NumberSize;
|
||||||
let initialNum = num;
|
let initialNum = num;
|
||||||
let variance = Math.pow(10, decimal);
|
let variance = Math.pow(10, decimal);
|
||||||
|
@ -30,11 +31,6 @@ export class NumberUtils {
|
||||||
num = num / 1000;
|
num = num / 1000;
|
||||||
num = Math.round(num * variance) / variance;
|
num = Math.round(num * variance) / variance;
|
||||||
roundNum = {number: num, size: "K", count: initialNum};
|
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 {
|
} else {
|
||||||
roundNum = {number: num, size: "", count: initialNum};
|
roundNum = {number: num, size: "", count: initialNum};
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,23 @@ import {DecimalPipe} from "@angular/common";
|
||||||
export class NumberRoundPipe implements PipeTransform {
|
export class NumberRoundPipe implements PipeTransform {
|
||||||
decimalPipe: DecimalPipe = new DecimalPipe("en");
|
decimalPipe: DecimalPipe = new DecimalPipe("en");
|
||||||
|
|
||||||
constructor() {}
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
transform(value: number, ...args: any[]): any {
|
/**
|
||||||
let level = Level.NONE;
|
* 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;
|
let decimal = 0;
|
||||||
if(args[0]) {
|
if (args[0]) {
|
||||||
level = args[0];
|
level = args[0];
|
||||||
}
|
}
|
||||||
if(args[1]) {
|
if (args[1]) {
|
||||||
decimal = args[1];
|
decimal = args[1];
|
||||||
}
|
}
|
||||||
let size: NumberSize = NumberUtils.roundNumber(value, level, decimal);
|
let size: NumberSize = NumberUtils.roundNumber(value, level, decimal);
|
||||||
return this.decimalPipe.transform(size.number) + (size.size?'<span class="number-size">' + size.size + '</span>':'');
|
return this.decimalPipe.transform(size.number) + (size.size ? '<span class="number-size">' + size.size + '</span>' : '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue