PercentageDoubleConverter extends GroupingStringToDoubleConverter { @Override public Result<Double> convertToModel(String value, ValueContext context) { value = value == null ? null : value.replace("%", ""); return super.convertToModel(value, context); } 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 testConvertToModel() { PercentageDoubleConverter converter = new PercentageDoubleConverter("message", 2, false); Result<Double> result = converter.convertToModel("3,14%", new ValueContext(new Locale("nl"))); assertEquals(3.14, result.getOrThrow(r -> new OCSRuntimeException()), 0.001); result = converter.convertToModel("3,14", new ValueContext(new Locale("nl"))); assertEquals(3.14, result.getOrThrow(r -> new OCSRuntimeException()), 0.001); converter = new PercentageDoubleConverter("message", 2, false); result = converter.convertToModel("3.14%", new ValueContext(Locale.US)); assertEquals(3.14, result.getOrThrow(r -> new OCSRuntimeException()), 0.001); assertNull(converter.convertToModel(null, new ValueContext(new Locale("nl"))) .getOrThrow(r -> new OCSRuntimeException())); }