@Test public void totalAmount() { final CurrencyConverter converter = new CurrencyConverter(new BigDecimal("200")); myAssertEquals(BigDecimal.ZERO, converter.convertToObject("0", locale)); myAssertEquals(BigDecimal.ZERO, converter.convertToObject("0 " + CURRENCY, locale)); myAssertEquals(BigDecimal.ZERO, converter.convertToObject("0" + CURRENCY, locale)); myAssertEquals(BigDecimal.ZERO, converter.convertToObject("0,00 " + CURRENCY, locale)); myAssertEquals(new BigDecimal("-10"), converter.convertToObject("-10,00 " + CURRENCY, locale)); myAssertEquals(new BigDecimal("1234.56"), converter.convertToObject("1.234,56 " + CURRENCY, locale)); myAssertEquals(new BigDecimal("100"), converter.convertToObject("50%", locale)); myAssertEquals(new BigDecimal("0"), converter.convertToObject("0 %", locale)); myAssertEquals(new BigDecimal("200"), converter.convertToObject("100,0 %", locale)); myAssertEquals(new BigDecimal("85.4"), converter.convertToObject("42,7 %", locale)); }
@Override public BigDecimal convertToObject(String value, final Locale locale) { value = StringUtils.trimToEmpty(value); if (value.endsWith(currency) == true) { value = value.substring(0, value.length() - 1).trim(); } else if (totalAmount != null && value.endsWith("%") == true) { value = value.substring(0, value.length() - 1).trim(); final BigDecimal percentage = super.convertToObject(value, locale); return totalAmount.multiply(percentage).divide(NumberHelper.HUNDRED, RoundingMode.HALF_UP); } return super.convertToObject(value, locale); }
CurrencyConverter extends BigDecimalConverter { @Override public BigDecimal convertToObject(String value, final Locale locale) { value = StringUtils.trimToEmpty(value); if (value.endsWith(currency) == true) { value = value.substring(0, value.length() - 1).trim(); } else if (totalAmount != null && value.endsWith("%") == true) { value = value.substring(0, value.length() - 1).trim(); final BigDecimal percentage = super.convertToObject(value, locale); return totalAmount.multiply(percentage).divide(NumberHelper.HUNDRED, RoundingMode.HALF_UP); } return super.convertToObject(value, locale); } }
CurrencyConverter extends BigDecimalConverter { @Override public BigDecimal convertToObject(String value, final Locale locale) { value = StringUtils.trimToEmpty(value); if (value.endsWith(currency) == true) { value = value.substring(0, value.length() - 1).trim(); } else if (totalAmount != null && value.endsWith("%") == true) { value = value.substring(0, value.length() - 1).trim(); final BigDecimal percentage = super.convertToObject(value, locale); return totalAmount.multiply(percentage).divide(NumberHelper.HUNDRED, RoundingMode.HALF_UP); } return super.convertToObject(value, locale); } CurrencyConverter();  CurrencyConverter(final BigDecimal totalAmount); }
CurrencyConverter extends BigDecimalConverter { @Override public BigDecimal convertToObject(String value, final Locale locale) { value = StringUtils.trimToEmpty(value); if (value.endsWith(currency) == true) { value = value.substring(0, value.length() - 1).trim(); } else if (totalAmount != null && value.endsWith("%") == true) { value = value.substring(0, value.length() - 1).trim(); final BigDecimal percentage = super.convertToObject(value, locale); return totalAmount.multiply(percentage).divide(NumberHelper.HUNDRED, RoundingMode.HALF_UP); } return super.convertToObject(value, locale); } CurrencyConverter();  CurrencyConverter(final BigDecimal totalAmount); @Override BigDecimal convertToObject(String value, final Locale locale); @Override String convertToString(final BigDecimal value, final Locale locale); }
CurrencyConverter extends BigDecimalConverter { @Override public BigDecimal convertToObject(String value, final Locale locale) { value = StringUtils.trimToEmpty(value); if (value.endsWith(currency) == true) { value = value.substring(0, value.length() - 1).trim(); } else if (totalAmount != null && value.endsWith("%") == true) { value = value.substring(0, value.length() - 1).trim(); final BigDecimal percentage = super.convertToObject(value, locale); return totalAmount.multiply(percentage).divide(NumberHelper.HUNDRED, RoundingMode.HALF_UP); } return super.convertToObject(value, locale); } CurrencyConverter();  CurrencyConverter(final BigDecimal totalAmount); @Override BigDecimal convertToObject(String value, final Locale locale); @Override String convertToString(final BigDecimal value, final Locale locale);  }