How to convert currency formatted String back to a BigDecimal? (using Java NumberFormat)

android, java, locale, number-formatting

Solution

    String s = "100000";
    Locale dutch = new Locale("nl", "NL");
    NumberFormat numberFormatDutch = NumberFormat.getCurrencyInstance(dutch);

    String c = numberFormatDutch.format(new BigDecimal(s.toString()));
    System.out.println("Currency Format: "+ c);
    try {
        Number  d = numberFormatDutch.parse(c);
        BigDecimal bd = new BigDecimal(d.toString());
        System.out.println(bd);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Currency Format: € 100.000,00

100000

Problem

In my Android app I've got an EditText from which I take a number, and convert that to a BigDecimal, and from there to a local Currency formatting: ``` String s = "100000"; Locale dutch = new Locale("nl", "NL"); NumberFormat numberFormatDutch = NumberFormat.getCurrencyInstance(dutch); Log.e(this, "Currency Format: "+ numberFormatDutch.format(new BigDecimal(s.toString()))); ``` This prints out €100.000,00 like expected. I now however, want to convert this back into a BigDecimal. Is there a way that I can convert a locally formatted currency string back to a BigDecimal?

Original source