最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Intl.NumberFormat reformatting the currencySymbol - Stack Overflow

programmeradmin2浏览0评论

I'm using JS' Intl.Numberformat function, but is there a way I can replace the output that's now: ANG12.45 Format to: fl. 12.45 So replace the default currencyDisplay to a custom naming including a space between the symbol and value?

value = parseFloat(value);
var formatter = new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'ANG', 
    currencyDisplay: 'symbol',
    minimumFractionDigits: 2
});
return formatter.format(value);

I'm using JS' Intl.Numberformat function, but is there a way I can replace the output that's now: ANG12.45 Format to: fl. 12.45 So replace the default currencyDisplay to a custom naming including a space between the symbol and value?

value = parseFloat(value);
var formatter = new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'ANG', 
    currencyDisplay: 'symbol',
    minimumFractionDigits: 2
});
return formatter.format(value);
Share Improve this question edited Aug 6, 2023 at 14:22 Penny Liu 17.6k5 gold badges86 silver badges108 bronze badges asked May 14, 2018 at 9:42 user1469734user1469734 82114 gold badges52 silver badges94 bronze badges 3
  • Did you solve the problem? – camelsWriteInCamelCase Commented May 22, 2018 at 22:08
  • 1 Yes: return formatter.format(value).replace("ANG", "ƒ "); – user1469734 Commented May 23, 2018 at 11:05
  • Then you need to accept your own answer. – camelsWriteInCamelCase Commented May 23, 2018 at 12:11
Add a ment  | 

2 Answers 2

Reset to default 8
return formatter.format(value).replace("ANG", "ƒ ");

This can not be done with the Intl.NumberFormat object, because the value of the "currency" parameter must be in ISO 4217 currency codes list and there is no "FL" there.

发布评论

评论列表(0)

  1. 暂无评论