ICU-13060 Minor tweak to CurrencyUsage override; allows CurrencyUsage without a currency pattern.

X-SVN-Rev: 39954
This commit is contained in:
Shane Carr 2017-03-29 06:33:41 +00:00
parent bd370f23a8
commit bd7655a38e
2 changed files with 21 additions and 10 deletions

View file

@ -107,6 +107,7 @@ public class CurrencyFormat {
public static boolean useCurrency(IProperties properties) {
return ((properties.getCurrency() != null)
|| properties.getCurrencyPluralInfo() != null
|| properties.getCurrencyUsage() != null
|| AffixPatternUtils.hasCurrencySymbols(properties.getPositivePrefixPattern())
|| AffixPatternUtils.hasCurrencySymbols(properties.getPositiveSuffixPattern())
|| AffixPatternUtils.hasCurrencySymbols(properties.getNegativePrefixPattern())
@ -242,25 +243,25 @@ public class CurrencyFormat {
currency = DEFAULT_CURRENCY;
}
Currency.CurrencyUsage currencyUsage = properties.getCurrencyUsage();
if (currencyUsage == null) {
currencyUsage = CurrencyUsage.STANDARD;
}
CurrencyUsage _currencyUsage = properties.getCurrencyUsage();
int _minFrac = properties.getMinimumFractionDigits();
int _maxFrac = properties.getMaximumFractionDigits();
double incrementDouble = currency.getRoundingIncrement(currencyUsage);
int fractionDigits = currency.getDefaultFractionDigits(currencyUsage);
CurrencyUsage effectiveCurrencyUsage =
(_currencyUsage != null) ? _currencyUsage : CurrencyUsage.STANDARD;
double incrementDouble = currency.getRoundingIncrement(effectiveCurrencyUsage);
int fractionDigits = currency.getDefaultFractionDigits(effectiveCurrencyUsage);
destination.setRoundingMode(properties.getRoundingMode());
destination.setMinimumIntegerDigits(properties.getMinimumIntegerDigits());
destination.setMaximumIntegerDigits(properties.getMaximumIntegerDigits());
int _minFrac = properties.getMinimumFractionDigits();
int _maxFrac = properties.getMaximumFractionDigits();
if (_minFrac >= 0 || _maxFrac >= 0) {
// User override
if (_currencyUsage == null && (_minFrac >= 0 || _maxFrac >= 0)) {
// User override of fraction length
destination.setMinimumFractionDigits(_minFrac);
destination.setMaximumFractionDigits(_maxFrac);
} else {
// Currency rounding
destination.setMinimumFractionDigits(fractionDigits);
destination.setMaximumFractionDigits(fractionDigits);
}

View file

@ -5192,6 +5192,16 @@ public class NumberFormatTest extends TestFmwk {
assertEquals("Should not consume the trailing bidi or whitespace", 4, ppos.getIndex());
}
@Test
public void testCustomCurrencyUsageOverridesPattern() {
DecimalFormat df = new DecimalFormat("#,##0.###");
expect2(df, 1234, "1,234");
df.setCurrencyUsage(CurrencyUsage.STANDARD);
expect2(df, 1234, "1,234.00");
df.setCurrencyUsage(null);
expect2(df, 1234, "1,234");
}
@Test
public void testSignificantDigitsMode() {
String[][] allExpected = {