Best way to remove thousand separators from string amount using a regex

前端 未结 5 1943
孤城傲影
孤城傲影 2021-01-12 17:59

I have variables that contain amounts and would like to remove the (US) thousand separators but also have to cover the scenario that there may be non-US formatted amounts wh

5条回答
  •  时光取名叫无心
    2021-01-12 18:34

    myVar = myVar.replace(/([.,])(\d\d\d\D|\d\d\d$)/g,'$2');

    Removes the period . or comma , when used as a thousand separator.

提交回复
热议问题