给定一个值1000.5
,我想将其格式化为1,000.50 USD
(尾随货币代码是最相关的部分)。性能也很重要,因为将针对数百万个值发布格式。因此,不鼓励使用正则表达式。
您能否使用Intl.NumberFormat或其他一些标准化的 JavaScript 数字格式化 API 来完成此操作?
例子:
const formatter = Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', currencyDisplay: 'code' }) formatter.format(1000.5)
实际的:
1,000.50 美元
预期的:
1,000.50 美元
肥皂起泡泡
相关分类