給定一個值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 美元
如何在 Javascript 中使用尾隨 ISO 代碼格式化貨幣?
BIG陽
2022-12-29 16:43:29