0

I have my input with currencyPipe, it works, but sometimes i need to add decimals numbers, but with the code that i'm using i can't do it.

    this.form.valueChanges.subscribe(res => {
  if(res.total_actives_amount){
    this.form.patchValue({
      total_actives_amount: this.currencyPipe.transform(res.total_actives_amount.replace(/\D/g, '').replace(/^0+/, ''), 'USD', 'symbol', '1.0-0')
    }, {emitEvent: false});
  }
})

I think that the problem is this line:

total_actives_amount: this.currencyPipe.transform(res.total_actives_amount.replace(/\D/g, '').replace(/^0+/, ''), 'USD', 'symbol', '1.0-0')
R. Richards
  • 24,603
  • 10
  • 64
  • 64

1 Answers1

1

The transform method inside currency pipe has the following parameters:

transform(
   value: string | number,
   currencyCode: string,
   display: string | boolean,
   digitsInfo: string,
   locale: string
) {...}

The digitsInfo takes the following format:

{minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}

the value you specified for the digitsInfo is 1.0-0

minIntegerDigits = 1

minFractionDigits = 0

maxFractionDigits = 0

to display decimal numbers you have to change minFractionDigits and the maxFractionDigits to a larger number than 0

for example

1.1-3

this will show at least one decimal number and at most 3 decimal numbers

reference angular.io/currency

Ahmed Shehatah
  • 658
  • 5
  • 11