Removing Dollar and comma from string

Varun Vishnoi picture Varun Vishnoi · Dec 3, 2013 · Viewed 51.8k times · Source

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

String liveprice = "$123,456.78";

Answer

Prabhakaran Ramaswamy picture Prabhakaran Ramaswamy · Dec 3, 2013

do like this

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

output

123456.78