How to use Angular number pipe in Component and Service

Viewed 10462

I use below number pipe to format quantity:

{{tradcollapse?.quantity | number}}

example show as 1,234,0.

I want to use this format quantity in Component with filtered, not a number with as it is 12340. How can I implement it?

3 Answers

In case someone else needs to do this, you now have to import DecimalPipe instead of NumberPipe.

e.g.

import { DecimalPipe } from '@angular/common';

Then transform e.g.

// Format cost amount to currency to improve readability of number.
formatToCurrency(r) {
  let val = this.decimalPipe.transform(r.get('Amount').value, '1.2-2')
  r.get('Amount').setValue(val);
}

You can try with formatNumber function Angular 8.

import { formatNumber } from '@angular/common';

//wherever is needed

console.log(formatNumber(this.numberValue,"en-US", "1.2-3"));

Refer https://angular.io/api/common/formatNumber

Related