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

前端 未结 5 1914
孤城傲影
孤城傲影 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:26

    if (string.match(/\.\d{2}$/) {
        string = string.replace(',', '');
    }
    

    or

    string.replace(/,(?=.*\.\d+)/g, '');
    

提交回复
热议问题