【问题标题】:Intl NuberFormat bad thai currencyIntl NumberFormat 泰国货币错误
【发布时间】:2019-05-14 10:32:53
【问题描述】:

我正在尝试为应用程序获取一些 currencyFormatter,但遇到了一些问题。

我能够正确使用带有相应符号的大多数货币格式,即

var usd = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' }).format(12345);
var euro = new Intl.NumberFormat('pt-br', { style: 'currency', currency: 'EUR' }).format(12345);
var deEuro = new Intl.NumberFormat('de', { style: 'currency', currency: 'EUR' }).format(12345);

£12,345.00
€12.345,00
12.345,00 €

但是当我想格式化为泰铢时,它没有显示฿ 符号。相反,它是泰铢……我做错了什么还是没有映射?

var thai = new Intl.NumberFormat('th', { style: 'currency', currency: 'THB' }).format(12345);


THB 12,345.00

我可以在之后替换字符串,但这样做对我来说不方便......

var thai = new Intl.NumberFormat('th', { style: 'currency', currency: 'THB' }).format(12345).replace(/\b(\w*THB\w*)\b/, '฿ ');

฿ 12,345.00

【问题讨论】:

标签: javascript ecmascript-6 number-formatting intl


【解决方案1】:

试试这个

new Intl.NumberFormat('th-TH', { style: 'currency', currency: 'THB' }).format(12345)

输出:“฿12,345.00”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 2018-11-22
    • 2010-09-19
    相关资源
    最近更新 更多