use of org.joda.money.CurrencyUnit in project killbill by killbill.
the class DefaultInvoiceFormatter method getFormattedAmountByLocaleAndInvoiceCurrency.
// Returns the formatted amount with the correct currency symbol that is get from the invoice currency.
private String getFormattedAmountByLocaleAndInvoiceCurrency(final BigDecimal amount) {
final String invoiceCurrencyCode = invoice.getCurrency().toString();
final CurrencyUnit currencyUnit = CurrencyUnit.of(invoiceCurrencyCode);
final DecimalFormat numberFormatter = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
final DecimalFormatSymbols dfs = numberFormatter.getDecimalFormatSymbols();
dfs.setInternationalCurrencySymbol(currencyUnit.getCode());
try {
Currency currency = Currency.fromCode(invoiceCurrencyCode);
dfs.setCurrencySymbol(currency.getSymbol());
} catch (final IllegalArgumentException e) {
dfs.setCurrencySymbol(currencyUnit.getSymbol(locale));
}
numberFormatter.setDecimalFormatSymbols(dfs);
numberFormatter.setMinimumFractionDigits(currencyUnit.getDecimalPlaces());
numberFormatter.setMaximumFractionDigits(currencyUnit.getDecimalPlaces());
return numberFormatter.format(amount.doubleValue());
}
Aggregations