【发布时间】:2017-09-20 16:51:43
【问题描述】:
在我的 Angular 2.0 应用程序中,我从 webapi 获取价格,我需要重新格式化它们,例如:
这是我从 webapi 得到的:40260000 作为价格,我需要将其格式化为 40.260 HUF,即匈牙利货币。
我尝试了一些解决方案,但似乎我错过了一些东西:
console.log(this.flatOffer.Price.toLocaleString('hu-HU'));
或
console.log(new Intl.NumberFormat('hu-HU').format(this.flatOffer.Price));
感谢任何提示。
【问题讨论】:
-
是否需要格式化才能在视图中显示?
-
@alexmac 是的
-
仔细查看NumberFormat 文档。如果您希望格式化为货币,它有一个选项参数需要使用。
-
尝试调查CurrencyPipe。
-
货币基于区域设置,请参阅此副本中的答案:stackoverflow.com/questions/39634025/…
标签: javascript angular typescript ecmascript-6