Display amount as currency with fractions only when currency type has fractions

后端 未结 4 1335
庸人自扰
庸人自扰 2020-12-22 12:59

I use this code to display amount:

 {{transaction.amount}} {{transaction.currency}}

Currently I have this output: 5603

4条回答
  •  眼角桃花
    2020-12-22 13:18

    You can do it by using the in-built currency pipe as

    
         
            {{ transaction.amount | currency:'JPY':'symbol':'1.0-0'}}
         
         
            {{ transaction.amount | currency:'USD':'symbol':'1.2-2'}}
         
         
            {{ transaction.amount | currency:'USD':'symbol':'1.2-2'}}
         
    
    

    The last attribute to the currency pipe filter depicts the digits info in format

    {minIntegerDigits}.{minFractionDigits}-{maxFractionDigits}
    

    Here the US currency will have atleast one integer digit with minimum and maximum of 2 digits whereas Japanese currency will have no fractions

提交回复
热议问题