-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
  • 357
  • 1
  • 6
  • 15

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
  • 60,707
  • 10
  • 101
  • 129