@Test public void shouldUseTheDefaultLocale() throws ParseException { when(request.getSession()).thenReturn(session); when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request")).thenReturn(null); when(session.getAttribute("javax.servlet.jsp.jstl.fmt.locale.session")). thenReturn(null); when(context.getAttribute("javax.servlet.jsp.jstl.fmt.locale.application")). thenReturn(null); when(context.getInitParameter("javax.servlet.jsp.jstl.fmt.locale")). thenReturn(null); when(request.getLocale()).thenReturn(Locale.getDefault()); DecimalFormat fmt = new DecimalFormat("##0,00"); fmt.setMinimumFractionDigits(2); double theValue = 10.00d; String formattedValue = fmt.format(theValue); assertThat((Double) converter.convert(formattedValue, double.class, bundle), is(equalTo(theValue))); }
public Double convert(String value, Class<? extends Double> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return 0d; } 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)); } }
LocaleBasedPrimitiveDoubleConverter implements Converter<Double> { public Double convert(String value, Class<? extends Double> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return 0d; } 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)); } } }
LocaleBasedPrimitiveDoubleConverter implements Converter<Double> { public Double convert(String value, Class<? extends Double> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return 0d; } 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)); } } LocaleBasedPrimitiveDoubleConverter(Localization localization); }
LocaleBasedPrimitiveDoubleConverter implements Converter<Double> { public Double convert(String value, Class<? extends Double> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return 0d; } 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)); } } LocaleBasedPrimitiveDoubleConverter(Localization localization); Double convert(String value, Class<? extends Double> type, ResourceBundle bundle); }
LocaleBasedPrimitiveDoubleConverter implements Converter<Double> { public Double convert(String value, Class<? extends Double> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return 0d; } 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)); } } LocaleBasedPrimitiveDoubleConverter(Localization localization); Double convert(String value, Class<? extends Double> type, ResourceBundle bundle);  }