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