I have a String that represents a dollar amount and am trying to use .replaceAll("$", "") on it to prepare it for use with parseDouble(). However, when I run my app I'm still getting a java.lang.NumberFormatException: Invalid double: "$100.00"
so it seems that for whatever reason, replaceAll() isn't working. Can anyone suggest why?
Here's the block of code affected:
public String subtractCurrenciesToString(String value1, String value2){
String stringValue1 = value1.replaceAll("$", "");
String stringValue2 = value2.replaceAll("$", "");
Double currency1 = Double.parseDouble(stringValue1);
Double currency2 = Double.parseDouble(stringValue2);
return MoneyFormat.format(currency1 - currency2);
}
NOTE: MoneyFormat is a NumberFormat object initialized with getCurrencyInstance().