【问题标题】:Format int num in money javascript [duplicate]在金钱javascript中格式化int num [重复]
【发布时间】:2018-09-07 14:30:27
【问题描述】:

我已经搜索过,但没有找到解决方案。我有一个产品列表,每个产品都有不同的价格:

ex1: 53990 例2:160115

如何将这些更改为货币格式?我来自巴西,所以 ex1 必须是:R$ 539,00 和 ex2:R$ 1.601,15

我已经尝试过下面的代码,但没有成功:

row.price.toFixed(3).replace(/(\d)(?=(\d{3})+\.)/g, '$1,')

【问题讨论】:

  • 请使用 sn-p 创建一个minimal reproducible example - 您的描述没有意义,并且有数千个示例如何格式化货币,包括 Indian Lahk 等

标签: javascript


【解决方案1】:

我的建议是使用accounting 库:

var accounting = require('accounting')
accounting.formatMoney(12345.67, {
  symbol: 'R$',
  decimal: ',',
  thousand: '.',
  format: '%s %v',
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 2012-01-28
    • 2017-02-19
    • 1970-01-01
    相关资源
    最近更新 更多