@Test public void testPercentage() { assertEquals("12.3%", UNDER_TEST.formatPercentage("0.1234", "1")); }
@Override public String formatPercentage(String numberString, String numberOfDigits) { if (numberString == null || numberString.isEmpty()) { return ""; } try { float value = Float.valueOf(numberString); if (value == 0) { return "-"; } int digits = Integer.valueOf(numberOfDigits); final NumberFormat formatter = DecimalFormat.getPercentInstance(bundle.getLocal()); formatter.setMaximumFractionDigits(digits); return formatter.format(value); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+numberString+"'.", e); throw new IllegalArgumentException(e); } }
ResourceLocalizer implements Localizer { @Override public String formatPercentage(String numberString, String numberOfDigits) { if (numberString == null || numberString.isEmpty()) { return ""; } try { float value = Float.valueOf(numberString); if (value == 0) { return "-"; } int digits = Integer.valueOf(numberOfDigits); final NumberFormat formatter = DecimalFormat.getPercentInstance(bundle.getLocal()); formatter.setMaximumFractionDigits(digits); return formatter.format(value); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+numberString+"'.", e); throw new IllegalArgumentException(e); } } }
ResourceLocalizer implements Localizer { @Override public String formatPercentage(String numberString, String numberOfDigits) { if (numberString == null || numberString.isEmpty()) { return ""; } try { float value = Float.valueOf(numberString); if (value == 0) { return "-"; } int digits = Integer.valueOf(numberOfDigits); final NumberFormat formatter = DecimalFormat.getPercentInstance(bundle.getLocal()); formatter.setMaximumFractionDigits(digits); return formatter.format(value); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+numberString+"'.", e); throw new IllegalArgumentException(e); } } ResourceLocalizer(LocalizationBundle bundle); }
ResourceLocalizer implements Localizer { @Override public String formatPercentage(String numberString, String numberOfDigits) { if (numberString == null || numberString.isEmpty()) { return ""; } try { float value = Float.valueOf(numberString); if (value == 0) { return "-"; } int digits = Integer.valueOf(numberOfDigits); final NumberFormat formatter = DecimalFormat.getPercentInstance(bundle.getLocal()); formatter.setMaximumFractionDigits(digits); return formatter.format(value); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+numberString+"'.", e); throw new IllegalArgumentException(e); } } ResourceLocalizer(LocalizationBundle bundle); @Override String formatDate(String dateString); @Override String formatDateTime(String dateString); @Override String formatTime(String dateString); @Override String getText(String key, String defaultText, Object... arguments); @Override String formatDuration(String duration); @Override String formatMoney(String amount, String currencyCode); @Override String formatInteger(String integerString); @Override String formatFloat(String numberString, String numberOfDigits); @Override String formatPercentage(String numberString, String numberOfDigits); @Override String formatMinutes(String durationString); }
ResourceLocalizer implements Localizer { @Override public String formatPercentage(String numberString, String numberOfDigits) { if (numberString == null || numberString.isEmpty()) { return ""; } try { float value = Float.valueOf(numberString); if (value == 0) { return "-"; } int digits = Integer.valueOf(numberOfDigits); final NumberFormat formatter = DecimalFormat.getPercentInstance(bundle.getLocal()); formatter.setMaximumFractionDigits(digits); return formatter.format(value); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+numberString+"'.", e); throw new IllegalArgumentException(e); } } ResourceLocalizer(LocalizationBundle bundle); @Override String formatDate(String dateString); @Override String formatDateTime(String dateString); @Override String formatTime(String dateString); @Override String getText(String key, String defaultText, Object... arguments); @Override String formatDuration(String duration); @Override String formatMoney(String amount, String currencyCode); @Override String formatInteger(String integerString); @Override String formatFloat(String numberString, String numberOfDigits); @Override String formatPercentage(String numberString, String numberOfDigits); @Override String formatMinutes(String durationString);  }