Search code examples
angulartypescriptionic-frameworkionic3angular-pipe

Ionic 3 currency formatting


I'm trying to format the currency with the following command

<h1>R$ {{item.valor | currency:"BRL":true:1.2 }}</h1> 

but this error is shown

digitsinfo.match is not a function

How can I get the money in the correct format in Ionic 3?


Solution

  • Take a look at the CurrencyPipe docs. The pipe expects following format:

    {{ value_expression | currency [ : currencyCode [ : display [ : digitsInfo [ : locale ] ] ] ] }}
    

    where digitsInfo is supposed to be

    a string which has a following format: {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}.

    (Source, emphasis is mine)

    So formatting your digitsInfo as a string should fix your error:

    <h1>R$ {{item.valor | currency:"BRL":true:"1.2" }}</h1>