openaire-library/utils/pipes/number-round.pipe.ts

24 lines
728 B
TypeScript

import {Pipe, PipeTransform} from "@angular/core";
import {Level, 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, ...args: any[]): any {
let level = Level.NONE;
let decimal = 0;
if(args[0]) {
level = args[0];
}
if(args[1]) {
decimal = args[1];
}
let size: NumberSize = NumberUtils.roundNumber(value, level, decimal);
return this.decimalPipe.transform(size.number) + (size.size?'<span class="number-size">' + size.size + '</span>':'');
}
}