使用逗号作为小数分隔符在Vaadin TextField中输入货币值

时间:2015-03-04 11:05:14

标签: vaadin currency decimal-point

我使用简单的TextField输入货币值,我想将其转移到BigDecimal。现在我想输入像“145,53”这样的值(逗号分隔的小数,作为€的通常货币值)。但是如果我使用“145.53”它只接受该值。

我如何以正确的方式应用它?

1 个答案:

答案 0 :(得分:2)

TextField设置自定义转换器。

开始
public class CurrencyConverter extends StringToNumberConverter {

    @Override
    protected NumberFormat getFormat(Locale locale) {
         if (locale == null) {
                locale = Locale.getDefault();
            }

            return NumberFormat.getCurrencyInstance(locale);
    }

}

如果您使用的是Spring,请使用LocaleContextHolder.getLocale()代替Locale.getDefault()

相关问题