0

myNumber is a number like '2.74' and I want to display it in HTML via interpolation like this:

<div> {{ myNumber | myCurrencyEuroPipe }} </div>

But I want to round the number to the whole number AND then not display any decimals. So e.g. from '2.74' to '3'. How can I achieve this, ideally with angular pipes? I already use a custom myCurrencyEuroPipe just to display an € at the end. Could you provide an example if Angular has its own pipes for this, or is a custom one necessary?

1

2 Answers 2

1

You can use toFixed()

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'myCurrencyEuro'
})
export class MyCurrencyEuroPipe implements PipeTransform {

  transform(value: number): string {
    return Number(value).toFixed() + '€';
  }

}
0

In your myCurrencyEuroPipe add this piece of code to make it work:

transform (value: number) {
      let result = value % 2 >= 0.5 ? Math.ceil(value) : Math.floor(value);
      // now pass this result to add the currency symbol.
}