PercentageDoubleConverter extends GroupingStringToDoubleConverter { @Override public String convertToPresentation(Double value, ValueContext context) { String result = super.convertToPresentation(value, context); return result == null ? null : result + "%"; } PercentageDoubleConverter(String message, int precision, boolean useGrouping); @Override String convertToPresentation(Double value, ValueContext context); @Override Result<Double> convertToModel(String value, ValueContext context);  }
@Test public void testConvertToPresentation() { PercentageDoubleConverter converter = new PercentageDoubleConverter("message", 2, false); String result = converter.convertToPresentation(3.143, new ValueContext(new Locale("nl"))); assertEquals("3,14%", result); result = converter.convertToPresentation(3000.1434, new ValueContext(new Locale("nl"))); assertEquals("3000,14%", result); converter = new PercentageDoubleConverter("message", 2, true); result = converter.convertToPresentation(3000.14, new ValueContext(new Locale("nl"))); assertEquals("3.000,14%", result); converter = new PercentageDoubleConverter("message", 2, false); result = converter.convertToPresentation(3.14, new ValueContext(Locale.US)); assertEquals("3.14%", result); converter = new PercentageDoubleConverter("message", 2, true); result = converter.convertToPresentation(3000.14, new ValueContext(Locale.US)); assertEquals("3,000.14%", result); assertNull(converter.convertToPresentation(null, new ValueContext(new Locale("nl")))); }