Assume we have the amount $12345.67
This can be converted into a Monetary value using joda money library with:
Money parsed = Money.parse("USD 12345.67");
//Now to display the amount according to the users locale we use:
MoneyFormatter mf = MoneyFormatterBuilder().appendAmountLocalized().toFormatter();
String localeString = mf.withLocale(Locale.getDefault()).print(parsed);
//Now assume the user is for example in Europe so the locale string would be 12.345,46
//Now assume he changes the amount inside a textfield to 12.345,47
Money changed = /*parse 12.345,47 (USD)*/
The question is how can I parse the localized String back to the monetary value (pay attention to the grouping digit which is a dot and the fraction digit with is a comma). This also has to work with every money value and every string that comes out from the above formatter.
Money.parse()
only works on this regex which does not fulfill the requirements [+-]?[0-9]*[.]?[0-9]*
Okay. Got it. You can use the MoneyFormatter vice versa. Documentation was just a bit unclear
MoneyFormatter mf = MoneyFormatterBuilder().appendAmountLocalized().toFormatter()
MoneyParseContext parsed = mf.withLocale(Locale.getDefault()).parse(amount,0);
parsed.setCurrency(currency);
Money money = Money.of(parsed.toBigMoney());