ICU-7667 In DecimalFormat::_format, deal with cases where two forms of rounding are specified - number of digits _and_ a rounding increment
X-SVN-Rev: 28132
This commit is contained in:
parent
79d1fa387f
commit
fa477f8a22
@ -1108,19 +1108,17 @@ DecimalFormat::_format(const DigitList &number,
|
||||
return appendTo;
|
||||
}
|
||||
|
||||
if (fRoundingIncrement == NULL) {
|
||||
if (fUseExponentialNotation || areSignificantDigitsUsed()) {
|
||||
int32_t sigDigits = precision();
|
||||
if (sigDigits > 0) {
|
||||
adjustedNum.round(sigDigits);
|
||||
}
|
||||
} else {
|
||||
// Fixed point format. Round to a set number of fraction digits.
|
||||
int32_t numFractionDigits = precision();
|
||||
adjustedNum.roundFixedPoint(numFractionDigits);
|
||||
if (fUseExponentialNotation || areSignificantDigitsUsed()) {
|
||||
int32_t sigDigits = precision();
|
||||
if (sigDigits > 0) {
|
||||
adjustedNum.round(sigDigits);
|
||||
}
|
||||
} else {
|
||||
// Fixed point format. Round to a set number of fraction digits.
|
||||
int32_t numFractionDigits = precision();
|
||||
adjustedNum.roundFixedPoint(numFractionDigits);
|
||||
}
|
||||
|
||||
|
||||
return subformat(appendTo, handler, adjustedNum, FALSE);
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ void addNumForTest(TestNode** root)
|
||||
TESTCASE(TestNumberFormat);
|
||||
TESTCASE(TestSpelloutNumberParse);
|
||||
TESTCASE(TestSignificantDigits);
|
||||
TESTCASE(TestSigDigRounding);
|
||||
TESTCASE(TestNumberFormatPadding);
|
||||
TESTCASE(TestInt64Format);
|
||||
TESTCASE(TestNonExistentCurrency);
|
||||
@ -886,6 +887,43 @@ static void TestSignificantDigits()
|
||||
unum_close(fmt);
|
||||
}
|
||||
|
||||
static void TestSigDigRounding()
|
||||
{
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UChar expected[128];
|
||||
UChar result[128];
|
||||
char temp1[128];
|
||||
char temp2[128];
|
||||
UNumberFormat* fmt;
|
||||
double d = 123.4;
|
||||
|
||||
fmt=unum_open(UNUM_DECIMAL, NULL, 0, NULL /* "en_US"*/, NULL, &status);
|
||||
if (U_FAILURE(status)) {
|
||||
log_err("got unexpected error for unum_open: '%s'\n", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
unum_setAttribute(fmt, UNUM_LENIENT_PARSE, FALSE);
|
||||
unum_setAttribute(fmt, UNUM_SIGNIFICANT_DIGITS_USED, TRUE);
|
||||
unum_setAttribute(fmt, UNUM_MAX_SIGNIFICANT_DIGITS, 2);
|
||||
// unum_setAttribute(fmt, UNUM_MAX_FRACTION_DIGITS, 0);
|
||||
|
||||
unum_setAttribute(fmt, UNUM_ROUNDING_MODE, UNUM_ROUND_UP);
|
||||
unum_setDoubleAttribute(fmt, UNUM_ROUNDING_INCREMENT, 20.0);
|
||||
|
||||
(void)unum_formatDouble(fmt, d, result, sizeof(result) / sizeof(result[0]), NULL, &status);
|
||||
if(U_FAILURE(status))
|
||||
{
|
||||
log_err("Error in formatting using unum_formatDouble(.....): %s\n", myErrorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
u_uastrcpy(expected, "140");
|
||||
if(u_strcmp(result, expected)!=0)
|
||||
log_err("FAIL: Error in unum_formatDouble result %s instead of %s\n", u_austrcpy(temp1, result), u_austrcpy(temp2, expected) );
|
||||
|
||||
unum_close(fmt);
|
||||
}
|
||||
|
||||
static void TestNumberFormatPadding()
|
||||
{
|
||||
UChar *result=NULL;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2009, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2010, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/********************************************************************************
|
||||
@ -38,6 +38,11 @@ static void TestSpelloutNumberParse(void);
|
||||
**/
|
||||
static void TestSignificantDigits(void);
|
||||
|
||||
/**
|
||||
* The function used to test Number format API rounding with significant digits
|
||||
**/
|
||||
static void TestSigDigRounding(void);
|
||||
|
||||
/**
|
||||
* The function used to test the Number format API with padding
|
||||
**/
|
||||
|
Loading…
Reference in New Issue
Block a user