Here is my code:
private double stripCurrency(String sBudget) {
DecimalFormat formatter = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.US);
DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
symbols.setCurrencySymbol("");
formatter.setDecimalFormatSymbols(symbols);
double d = Double.valueOf(formatter.format(sBudget)); // Line 52 in LogCat
return d;
}
Here is LogCat:
09-16 10:12:07.641: E/AndroidRuntime(1463): at java.text.NumberFormat.format(NumberFormat.java:304)
09-16 10:12:07.641: E/AndroidRuntime(1463): at java.text.DecimalFormat.format(DecimalFormat.java:702)
09-16 10:12:07.641: E/AndroidRuntime(1463): at java.text.Format.format(Format.java:93)
09-16 10:12:07.641: E/AndroidRuntime(1463): at com.---.---.GasUtil.stripCurrency(GasUtil.java:52)
This happens when opening app for the first time. The passed in String is the SharedPreference
default of "100".
What I am trying to do:
There should be a String
stored in SharedPreferences
and I convert that to a double. An older version of the app allowed for currency symbols in the String. So I am trying to sanitize from that old way. So I am formatting it to strip out old currency symbols and turning into a double. Not sure if my above code is the best way to do that, even after I resolve this bug, or if there is a better way? So I need to sanitize in a way that will handle both correct and bad formatting.