Is there a way to use math functions in AngularJS bindings?
e.g.
The percentage is {{Math.round(100*count/total)}}%
Angular Typescript example using a pipe.
math.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'math',
})
export class MathPipe implements PipeTransform {
transform(value: number, args: any = null):any {
if(value) {
return Math[args](value);
}
return 0;
}
}
Add to @NgModule declarations
@NgModule({
declarations: [
MathPipe,
then use in your template like so:
{{(100*count/total) | math:'round'}}