Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Angular number pipe in Component and Service

Tags:

angular

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?

like image 675
Victor Guan Avatar asked Jun 30 '17 11:06

Victor Guan


2 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);
}
like image 76
Danmar Herholdt Avatar answered Sep 23 '22 18:09

Danmar Herholdt


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

like image 33
Srinivas Rampelli Avatar answered Sep 24 '22 18:09

Srinivas Rampelli