@Test public void testMoney() { assertEquals("1,234.57 $", UNDER_TEST.formatMoney("1234.567", "USD")); }
@Override public String formatMoney(String amount, String currencyCode) { if (amount == null || amount.isEmpty()) { return ""; } try { float value = Float.valueOf(amount); if (value == 0) { return "-"; } Currency currency = Currency.getInstance(currencyCode); final NumberFormat formatter = DecimalFormat.getInstance(bundle.getLocal()); formatter.setCurrency(currency); formatter.setMinimumFractionDigits(0); formatter.setMaximumFractionDigits(currency.getDefaultFractionDigits()); return formatter.format(value) + " " + currency.getSymbol(bundle.getLocal()); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+amount+"'.", e); throw new IllegalArgumentException(e); } }
ResourceLocalizer implements Localizer { @Override public String formatMoney(String amount, String currencyCode) { if (amount == null || amount.isEmpty()) { return ""; } try { float value = Float.valueOf(amount); if (value == 0) { return "-"; } Currency currency = Currency.getInstance(currencyCode); final NumberFormat formatter = DecimalFormat.getInstance(bundle.getLocal()); formatter.setCurrency(currency); formatter.setMinimumFractionDigits(0); formatter.setMaximumFractionDigits(currency.getDefaultFractionDigits()); return formatter.format(value) + " " + currency.getSymbol(bundle.getLocal()); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+amount+"'.", e); throw new IllegalArgumentException(e); } } }
ResourceLocalizer implements Localizer { @Override public String formatMoney(String amount, String currencyCode) { if (amount == null || amount.isEmpty()) { return ""; } try { float value = Float.valueOf(amount); if (value == 0) { return "-"; } Currency currency = Currency.getInstance(currencyCode); final NumberFormat formatter = DecimalFormat.getInstance(bundle.getLocal()); formatter.setCurrency(currency); formatter.setMinimumFractionDigits(0); formatter.setMaximumFractionDigits(currency.getDefaultFractionDigits()); return formatter.format(value) + " " + currency.getSymbol(bundle.getLocal()); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+amount+"'.", e); throw new IllegalArgumentException(e); } } ResourceLocalizer(LocalizationBundle bundle); }
ResourceLocalizer implements Localizer { @Override public String formatMoney(String amount, String currencyCode) { if (amount == null || amount.isEmpty()) { return ""; } try { float value = Float.valueOf(amount); if (value == 0) { return "-"; } Currency currency = Currency.getInstance(currencyCode); final NumberFormat formatter = DecimalFormat.getInstance(bundle.getLocal()); formatter.setCurrency(currency); formatter.setMinimumFractionDigits(0); formatter.setMaximumFractionDigits(currency.getDefaultFractionDigits()); return formatter.format(value) + " " + currency.getSymbol(bundle.getLocal()); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+amount+"'.", 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 formatMoney(String amount, String currencyCode) { if (amount == null || amount.isEmpty()) { return ""; } try { float value = Float.valueOf(amount); if (value == 0) { return "-"; } Currency currency = Currency.getInstance(currencyCode); final NumberFormat formatter = DecimalFormat.getInstance(bundle.getLocal()); formatter.setCurrency(currency); formatter.setMinimumFractionDigits(0); formatter.setMaximumFractionDigits(currency.getDefaultFractionDigits()); return formatter.format(value) + " " + currency.getSymbol(bundle.getLocal()); } catch(NumberFormatException e) { LoggerFactory.getLogger(getClass()).error("Can't convert to float '"+amount+"'.", 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);  }