You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Intl.NumberFormat参数使PGK窄符号显示为K?

问题

使用Intl.NumberFormat处理PGK(巴布亚新几内亚基那)货币时,设置currencyDisplay: "narrowSymbol"后,窄符号显示为PGK而非预期的K。要求不能替换Intl.NumberFormat函数,也不能在函数调用后添加额外代码,仅可修改调用时的参数。

原代码示例:

const number = 123456.789;

console.log(new Intl.NumberFormat('en', { style: 'currency', currency: 'PGK', currencyDisplay: "narrowSymbol", }).format(number));
// Expected output: "K 123.456,79"
// Output: "PGK 123.456,79"

console.log(new Intl.NumberFormat('en', { style: 'currency', currency: 'MMK', currencyDisplay: "narrowSymbol", }).format(number));
// Output: "K 123.456,79"

解决方案

将区域设置从通用的'en'改为巴布亚新几内亚的英语区域代码'en-PG',即可获取PGK的窄符号K。

修改后的代码:

const number = 123456.789;

console.log(new Intl.NumberFormat('en-PG', { style: 'currency', currency: 'PGK', currencyDisplay: "narrowSymbol" }).format(number));
// Output: "K 123,456.79"

说明

通用'en'区域的本地化数据中,未将PGK的窄符号定义为K,因此默认回退显示货币代码PGK;而'en-PG'作为巴布亚新几内亚的专属区域设置,其本地化规则明确将PGK的窄符号映射为K,符合预期需求。

内容的提问来源于stack exchange,提问作者Marcelo Colling

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 01:44:58