mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-20620 cap UNUM_MAX_FRACTION_DIGITS setting at 999
This commit is contained in:
parent
15aa50bd3c
commit
62914d1f07
2 changed files with 40 additions and 0 deletions
|
@ -1388,6 +1388,10 @@ void DecimalFormat::setMinimumIntegerDigits(int32_t newValue) {
|
|||
void DecimalFormat::setMaximumFractionDigits(int32_t newValue) {
|
||||
if (fields == nullptr) { return; }
|
||||
if (newValue == fields->properties.maximumFractionDigits) { return; }
|
||||
// cap for backward compatibility, formerly 340, now 999
|
||||
if (newValue > kMaxIntFracSig) {
|
||||
newValue = kMaxIntFracSig;
|
||||
}
|
||||
// For backwards compatibility, conflicting min/max need to keep the most recent setting.
|
||||
int32_t min = fields->properties.minimumFractionDigits;
|
||||
if (min >= 0 && min > newValue) {
|
||||
|
|
|
@ -73,6 +73,7 @@ static void Test12052_NullPointer(void);
|
|||
static void TestParseCases(void);
|
||||
static void TestSetMaxFracAndRoundIncr(void);
|
||||
static void TestIgnorePadding(void);
|
||||
static void TestSciNotationMaxFracCap(void);
|
||||
|
||||
#define TESTCASE(x) addTest(root, &x, "tsformat/cnumtst/" #x)
|
||||
|
||||
|
@ -112,6 +113,7 @@ void addNumForTest(TestNode** root)
|
|||
TESTCASE(TestParseCases);
|
||||
TESTCASE(TestSetMaxFracAndRoundIncr);
|
||||
TESTCASE(TestIgnorePadding);
|
||||
TESTCASE(TestSciNotationMaxFracCap);
|
||||
}
|
||||
|
||||
/* test Parse int 64 */
|
||||
|
@ -3439,4 +3441,38 @@ static void TestIgnorePadding(void) {
|
|||
}
|
||||
}
|
||||
|
||||
static void TestSciNotationMaxFracCap(void) {
|
||||
static const UChar* pat1 = u"#.##E+00;-#.##E+00";
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UNumberFormat* unum = unum_open(UNUM_PATTERN_DECIMAL, pat1, -1, "en_US", NULL, &status);
|
||||
if ( U_FAILURE(status) ) {
|
||||
log_data_err("unum_open UNUM_PATTERN_DECIMAL with scientific pattern for \"en_US\" fails with %s\n", u_errorName(status));
|
||||
} else {
|
||||
double value;
|
||||
UChar ubuf[kUBufMax];
|
||||
char bbuf[kBBufMax];
|
||||
int32_t ulen;
|
||||
|
||||
unum_setAttribute(unum, UNUM_MIN_FRACTION_DIGITS, 0);
|
||||
unum_setAttribute(unum, UNUM_MAX_FRACTION_DIGITS, 2147483647);
|
||||
ulen = unum_toPattern(unum, FALSE, ubuf, kUBufMax, &status);
|
||||
if ( U_SUCCESS(status) ) {
|
||||
u_austrncpy(bbuf, ubuf, kUBufMax);
|
||||
log_info("unum_toPattern (%d): %s\n", ulen, bbuf);
|
||||
}
|
||||
|
||||
for (value = 10.0; value < 1000000000.0; value *= 10.0) {
|
||||
status = U_ZERO_ERROR;
|
||||
ulen = unum_formatDouble(unum, value, ubuf, kUBufMax, NULL, &status);
|
||||
if ( U_FAILURE(status) ) {
|
||||
log_err("unum_formatDouble value %.1f status %s\n", value, u_errorName(status));
|
||||
} else if (u_strncmp(ubuf,u"1E+0",4) != 0) {
|
||||
u_austrncpy(bbuf, ubuf, kUBufMax);
|
||||
log_err("unum_formatDouble value %.1f expected result to begin with 1E+0, got %s\n", value, bbuf);
|
||||
}
|
||||
}
|
||||
unum_close(unum);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
|
Loading…
Add table
Reference in a new issue