Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular currency pipe no decimal value

Tags:

I am trying to use the currency pipe in angular to display a whole number price, I don't need it to add .00 to my number, the thing is, its not formatting it according to my instructions. here is my HTML:

              <h5 class="price"><span>{{billingInfo.amount | currency:billingInfo.currencyCode:'1.0-0'}}</span> {{billingInfo.period}}</h5> 

here is my ts:

ngOnInit() {       this.billingInfo = {amount: 100, currencyCode: 'USD', period: 'Hour'}; } 

and here is the output:

$100.00 Hour 

things I tried to do:

1.use the decimal number pipe(no good, the currency pipe turns it into a string)

2.add number formater(:1.0-0) to my currencyPipe but it seems to be ignored

what am I missing?

like image 897
Efim Rozovsky Avatar asked Mar 21 '18 10:03

Efim Rozovsky


People also ask

What is the different value of symbol display while using the currency pipe?

The display parameter can be “code” (currencycode will be displayed) or “symbol” or “symbol-narrow” or any other custom value. Few countries like Canada have two currency codes like symbol CA$ and symbol-narrow $. If the country locale does not have symbol-narrow, default symbol will be displayed.

What is the default value of minFractionDigits while using the DecimalPipe?

minFractionDigits : The minimum number of digits after the decimal point. Default is 0.


1 Answers

To remove .00 from the currency pipe you can use this pattern. See the digitsInfo section on CurrencyPipe for more information.

{{ amount | currency : 'USD' : 'symbol' : '1.0-0' }}  

If you don't need the decimal you can use the number pipe.

${{amount | number}} 
like image 146
chris cooley Avatar answered Sep 21 '22 08:09

chris cooley