简体   繁体   中英

Format long number to currency (Angular)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM