@Test public void shouldBeAbleToConvertWithENUS() { when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request")).thenReturn("en_US"); assertThat(converter.convert("10.00", BigDecimal.class, bundle), is(equalTo(new BigDecimal("10.00")))); assertThat(converter.convert("10.01", BigDecimal.class, bundle), is(equalTo(new BigDecimal("10.01")))); }
public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } }
LocaleBasedBigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } } }
LocaleBasedBigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } } LocaleBasedBigDecimalConverter(Localization localization); }
LocaleBasedBigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } } LocaleBasedBigDecimalConverter(Localization localization); BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle); }
LocaleBasedBigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } } LocaleBasedBigDecimalConverter(Localization localization); BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle);  }