Reputation: 1183
I use a simple TextField
to enter a currency value and i want to transfer it to a BigDecimal
. Now I want to enter values like "145,53" (comma separated decimals, as an usual currency value for €). But it only accepts the value if I use "145.53".
How can i apply this in a correct way?
Upvotes: 0
Views: 3281
Reputation: 10709
Set a custom converter for the TextField
.
Start with something like
public class CurrencyConverter extends StringToNumberConverter {
@Override
protected NumberFormat getFormat(Locale locale) {
if (locale == null) {
locale = Locale.getDefault();
}
return NumberFormat.getCurrencyInstance(locale);
}
}
If you are using Spring, use LocaleContextHolder.getLocale()
instead Locale.getDefault()
Upvotes: 2