MathContext mathContext = RoundingUtils.getMathContextOrUnlimited(properties);
boolean explicitMinMaxFrac = minFrac != -1 || maxFrac != -1;
boolean explicitMinMaxSig = minSig != -1 || maxSig != -1;
+ // Resolve min/max frac for currencies, required for the validation logic and for when minFrac or maxFrac was
+ // set (but not both) on a currency instance.
+ // NOTE: Increments are handled in "Rounder.constructCurrency()".
+ if (useCurrency) {
+ if (minFrac == -1 && maxFrac == -1) {
+ minFrac = currency.getDefaultFractionDigits(currencyUsage);
+ maxFrac = currency.getDefaultFractionDigits(currencyUsage);
+ } else if (minFrac == -1) {
+ minFrac = Math.min(maxFrac, currency.getDefaultFractionDigits(currencyUsage));
+ } else if (maxFrac == -1) {
+ maxFrac = Math.max(minFrac, currency.getDefaultFractionDigits(currencyUsage));
+ } else {
+ // No-op: user override for both minFrac and maxFrac
+ }
+ }
// Validate min/max int/frac.
// For backwards compatibility, minimum overrides maximum if the two conflict.
// The following logic ensures that there is always a minimum of at least one digit.
df.setMaximumFractionDigits(3);
expect2(df, 35.0, "$35.000");
df.setMinimumFractionDigits(-1);
- expect2(df, 35.0, "$35");
+ expect2(df, 35.0, "$35.00");
df.setMaximumFractionDigits(-1);
expect2(df, 35.0, "$35.00");
}
expect2(df, 100, "a100");
expect2(df, -100, "-a100");
}
+
+ @Test
+ public void TestCurrencyRoundingMinWithoutMax() {
+ NumberFormat currencyFormat = DecimalFormat.getCurrencyInstance(Locale.US);
+ currencyFormat.setCurrency(Currency.getInstance("AUD"));
+ currencyFormat.setMinimumFractionDigits(0);
+ expect(currencyFormat, 0.001, "A$0");
+
+ // NOTE: The size of the increment takes precedent over minFrac since ICU 59.
+ // CAD-Cash uses nickel rounding.
+ currencyFormat = DecimalFormat.getCurrencyInstance(Locale.US);
+ currencyFormat.setCurrency(Currency.getInstance("CAD"));
+ ((DecimalFormat)currencyFormat).setCurrencyUsage(CurrencyUsage.CASH);
+ currencyFormat.setMinimumFractionDigits(0);
+ // expect(currencyFormat, 0.08, "CA$0.1"); // ICU 58 and down
+ expect(currencyFormat, 0.08, "CA$0.10"); // ICU 59 and up
+ }
}