Removing Dollar and comma from string

前端 未结 11 1998
天涯浪人
天涯浪人 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:17

    do like this

    NumberFormat format = NumberFormat.getCurrencyInstance();
    Number number = format.parse("\$123,456.78");
    System.out.println(number.toString());
    

    output

    123456.78
    

提交回复
热议问题