having
let myNumber = Math.PI;
let myPrecision = 4;
How can I display myNumber
using myPrecision
?
<label> {{ myNumber | ???myPrecision }} </label>
One not really elegant, but solution, could be
<div> {{ myNumber | number: '1.' + myPrecision + '-' + myPrecision + }} </div>
PS.
After the Joosep's suggestion, I made a custom pipe, like this
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'precision' })
export class PrecisionPipe implements PipeTransform {
transform(value: number, precision: number): string {
return value.toFixed(precision);
}
}
so now I can use
<div> {{ myNumber | precision: myPrecision }} </div>