0

In my Angular 2.0 app I get prices from webapi and i need to format them again for example :

This is what i get from webapi : 40260000 as a price and i need to format it to 40.260 HUF which is Hungarian currency.

I tried some solutions but it seems that i missed something for example :

 console.log(this.flatOffer.Price.toLocaleString('hu-HU'));

or

console.log(new Intl.NumberFormat('hu-HU').format(this.flatOffer.Price));

I appreciate any hint.

Ben
  • 2,441
  • 1
  • 12
  • 16
peyman gilmour
  • 1,168
  • 2
  • 16
  • 35
  • Do you need format it to display in a view? – alexmac Sep 20 '17 at 16:55
  • @alexmac yes exactly – peyman gilmour Sep 20 '17 at 16:56
  • Look closer at the [NumberFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat) documentation. It has an options argument you need to use if you wish to format as currency. – Patrick Evans Sep 20 '17 at 17:00
  • Try to investigate [CurrencyPipe](https://angular.io/api/common/CurrencyPipe). – alexmac Sep 20 '17 at 17:04
  • Currency is based on locale, see answers in this duplicate: https://stackoverflow.com/questions/39634025/how-to-display-the-currency-symbol-to-the-right-in-angular-2 – Eeks33 Sep 20 '17 at 18:23

1 Answers1

0

If you're displaying the currency in a view, I would look into the Angular Currency Pipe.

Also look at the Angular Decimal Pipe to understand the second portion of formatting in the Currency Pipe.

You can pipe your expression similarily:

{{myCurrencyValue | currency:'HUF':false:'1.3-3'}}

Note: This may not be exactly what you want in terms of the decimal formatting, but it should give you a good idea as to how you can format the currency.

Ben
  • 2,441
  • 1
  • 12
  • 16
  • At the beginning i tried that one but what it shows is : HUF20,130,000.000. and i also need to put HUF at the right side :P – peyman gilmour Sep 20 '17 at 17:25