-1

I'm using jquery and I need to switch the order of commas and dots in all numbers.

For example:

120,400.50 -> 120.400,50

Comma for decimals and dot for the rest.

Thanks in advance.

Hector Landete
  • 337
  • 5
  • 14

1 Answers1

3

If you want to format the number - you can use the above comment by @Conduit (the possible duplicate).

If you have a known string (with commas and dots) and you want to replace them, you can use a regex with a replacement function:

s = '120,400.50'
console.log(s.replace(/([\.,])/g, a => { return a === '.' ? ',' : '.'} ))
Dekel
  • 57,326
  • 8
  • 92
  • 123