I have this function:
public void printCurrency(double currencyAmount, String lang, String country) {
Locale locale = new Locale(lang, country);
Currency currency = Currency.getInstance(locale);
NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
numberFormat.setMaximumFractionDigits(2);
Log.d(TAG, currency.getDisplayName() + ": " + numberFormat.format(currencyAmount));
}
Everytime I call this with the following:
double amount = 123456789012345.67d;
printCurrency(amount, "jp", "JP");
printCurrency(amount, "en", "GB");
printCurrency(amount, "en", "US");
My amount is always rounded like so:
> Japanese Yen: ¥123,456,789,012,346
> British Pound Sterling: £123,456,789,012,346.00
> US Dollar: $123,456,789,012,346.00
I need a solution that always give a 2-decimal-place amount (if applicable) such as
> Japanese Yen: ¥123,456,789,012,346
> British Pound Sterling: £123,456,789,012,345.67
> US Dollar: $123,456,789,012,345.67
I tried the following but same issue:
NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
numberFormat.setMaximumFractionDigits(2);
numberFormat.setRoundingMode(RoundingMode.UNNECESSARY);