Files
iTunes/dashboard/src/app/pipes/round.pipe.ts
Maxence G. de Montauzan 330adb4b9f Improve top played part
Sort by avg. play + Slice
Add round pipe
Comment ELS Service
2018-03-21 00:50:06 +01:00

22 lines
492 B
TypeScript

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'round'
})
export class RoundPipe implements PipeTransform {
/**
* Round a value
* @param value value to round
* @param precision number of numbers to keep after coma - 1 if unspecified
*/
transform(value: number, precision?: number): number {
if (precision === undefined) {
precision = 1;
}
const factor = Math.pow(10, precision);
return Math.round(value * factor) / factor;
}
}