Add number-rounf pipe
This commit is contained in:
parent
10130d368a
commit
92488d015b
|
@ -1,6 +1,6 @@
|
|||
export interface NumberSize {
|
||||
number: number;
|
||||
size: "M" | "K" | "";
|
||||
size: "B" | "M" | "K" | "";
|
||||
count: number;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,11 @@ export class NumberUtils{
|
|||
//console.log("Trying to round number: "+ num);
|
||||
var roundNum: NumberSize = null;
|
||||
var initialNum = num;
|
||||
if(num >= 1000000){
|
||||
if (num >= 1000000000) {
|
||||
num = num / 1000000;
|
||||
num = Math.round(num);
|
||||
roundNum = {number: num, size: "B", count: initialNum};
|
||||
} else if(num >= 1000000) {
|
||||
num=num/1000000;
|
||||
num= Math.round(num);
|
||||
roundNum = { number: num, size: "M", count: initialNum};
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import {NgModule} from "@angular/core";
|
||||
import {NumberRoundPipe} from "./number-round.pipe";
|
||||
|
||||
@NgModule({
|
||||
declarations: [NumberRoundPipe],
|
||||
exports: [NumberRoundPipe]
|
||||
|
||||
})
|
||||
export class NumberRoundModule {
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
import {Pipe, PipeTransform} from "@angular/core";
|
||||
import {NumberSize, NumberUtils} from "../number-utils.class";
|
||||
import {DecimalPipe} from "@angular/common";
|
||||
|
||||
@Pipe({name: 'numberRound'})
|
||||
export class NumberRoundPipe implements PipeTransform {
|
||||
decimalPipe: DecimalPipe = new DecimalPipe("en");
|
||||
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
transform(value: number): any {
|
||||
let size: NumberSize = NumberUtils.roundNumber(value);
|
||||
return this.decimalPipe.transform(size.number) + size.size;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue