Removing Dollar and comma from string

前端 未结 11 2028
天涯浪人
天涯浪人 2020-12-14 10:47

How can we remove dollar sign ($) and all comma(,) from same string? Would it be better to avoid regex?

String liveprice = \"$123,456.78\";
11条回答
  •  悲&欢浪女
    2020-12-14 11:28

    In my case, @Prabhakaran's answer did not work, someone can try this.

    String salary = employee.getEmpSalary().replaceAll("[^\\d.]", "");
    Float empSalary = Float.parseFloat(salary);
    

提交回复
热议问题