-1

Example = 123456789 = 123,456,789

is there any function that does the above or should I create one ?

Thank you

Andy
  • 61,948
  • 13
  • 68
  • 95

1 Answers1

1

Intl.NumberFormat has a localized number formatting.

That means if your browser is set to English you will get your expected format, but if the browser is set to German it will return the German format.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

const number = 123456.789;

console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number));
// expected output: "123.456,79 €"

// the Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number));
// expected output: "¥123,457"
Fels
  • 1,214
  • 2
  • 13
  • 27