I have an EditText which should work as follows (Android 2.3.3):
The user enters for instance 10,40 (which is 10 Euro and 40 Cents in EU currency) - I want to then take that String input and convert it to a BigDecimal (or Number etc...) for instance, for further internal computation.
The same should work if the user enters 10.40 (which - in the case of US Dollar would amount to 10 Dollars and 40 Cents), then take that String input and convert it to a BigDecimal (or Number etc...) for instance.
I tried the following (based on Michael Petrotta's answer here), which fails with "ParseException: Unparsable Number 10,40):
// German input
NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.GERMANY);
// User input
String value = "10,40";
Number valueParsed = formatter.parse(value);
I also tried "10,40 €" to no avail. So either I am misunderstanding the purpose of NumberFormat.parse or I'm on a wrong track all together...? I really want to avoid using Regular Expressions to replace the comma in "10,40" for the version should work internationally and I'd like some clean, Locale-based approach.
EDIT
I found this question which addresses the same issue - the correct answer uses the same approach that I do, so I tried again (using France as a Locale this time) but it fails nonetheless, which seems quite odd... The comment under the referenced question suggested using replaceAll(",", ".") which seems a bad idea to me, as some currencies use the comma as a divider for thousands, such as the US Dollar if I am not mistaken. I could however check the locale but that all seams shady :( and potentially erroneous ...