UNPKG

ng2-pipes

Version:
15 lines (11 loc) 326 B
import {PipeTransform, Pipe} from '@angular/core'; @Pipe({name: 'round'}) export class RoundPipe implements PipeTransform { transform(num: number, precision: number = 0): number { if (precision <= 0) { return Math.round(num); } const tho = 10 ** precision; return Math.round(num * tho) / tho; } }