如何使用货币格式?

How can I use currency formatted?

我需要一个帮助,在 JavaScript 的输出中,我得到这个输出:

100,000.00

我想将其更改为:

100.000,00

我该怎么做?

我认为下面的代码可以帮助您解决问题。如果有任何进一步的问题让我知道

  var str = "100,000.00"; 
  var res = str.replace(".", ",");
  document.write(res);

调查 Intl.NumberFormat。这是一个非常方便的原生 api.

var number = 876543.21;

// German uses comma as decimal separator and period for thousands
console.log(new Intl.NumberFormat('de-DE').format(number));

console.log(new Intl.NumberFormat('de-DE', {
  style: 'currency',
  currency: 'EUR'
}).format(number));

您可以使用图书馆 http://openexchangerates.github.io/accounting.js/ 例如:

accounting.formatMoney(4999.99, "€", 2, ".", ","); // €4.999,99