ICU-10419 Fix rounding in NumberFormat.
X-SVN-Rev: 34549
This commit is contained in:
parent
1746d496d4
commit
18b6e9fc60
@ -130,6 +130,7 @@ void NumberFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &n
|
||||
TESTCASE_AUTO(TestParseNegativeWithAlternateMinusSign);
|
||||
TESTCASE_AUTO(TestCustomCurrencySignAndSeparator);
|
||||
TESTCASE_AUTO(TestParseSignsAndMarks);
|
||||
TESTCASE_AUTO(Test10419RoundingWith0FractionDigits);
|
||||
TESTCASE_AUTO_END;
|
||||
}
|
||||
|
||||
@ -7284,4 +7285,38 @@ void NumberFormatTest::TestParseSignsAndMarks() {
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
DecimalFormat::ERoundingMode mode;
|
||||
double value;
|
||||
UnicodeString expected;
|
||||
} Test10419Data;
|
||||
|
||||
|
||||
// Tests that rounding works right when fractional digits is set to 0.
|
||||
void NumberFormatTest::Test10419RoundingWith0FractionDigits() {
|
||||
const Test10419Data items[] = {
|
||||
{ DecimalFormat::kRoundCeiling, 1.488, "2"},
|
||||
{ DecimalFormat::kRoundDown, 1.588, "1"},
|
||||
{ DecimalFormat::kRoundFloor, 1.888, "1"},
|
||||
{ DecimalFormat::kRoundHalfDown, 1.5, "1"},
|
||||
{ DecimalFormat::kRoundHalfEven, 2.5, "2"},
|
||||
{ DecimalFormat::kRoundHalfUp, 2.5, "3"},
|
||||
{ DecimalFormat::kRoundUp, 1.5, "2"},
|
||||
};
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
LocalPointer<DecimalFormat> decfmt((DecimalFormat *) NumberFormat::createInstance(Locale("en_US"), status));
|
||||
if (U_FAILURE(status)) {
|
||||
dataerrln("Failure creating DecimalFormat %s", u_errorName(status));
|
||||
return;
|
||||
}
|
||||
for (int32_t i = 0; i < sizeof(items) / sizeof(items[0]); ++i) {
|
||||
decfmt->setRoundingMode(items[i].mode);
|
||||
decfmt->setMaximumFractionDigits(0);
|
||||
UnicodeString actual;
|
||||
if (items[i].expected != decfmt->format(items[i].value, actual)) {
|
||||
errln("Expected " + items[i].expected + ", got " + actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* #if !UCONFIG_NO_FORMATTING */
|
||||
|
@ -175,6 +175,7 @@ class NumberFormatTest: public CalendarTimeZoneTest {
|
||||
void TestCustomCurrencySignAndSeparator();
|
||||
|
||||
void TestParseSignsAndMarks();
|
||||
void Test10419RoundingWith0FractionDigits();
|
||||
|
||||
private:
|
||||
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);
|
||||
|
Loading…
Reference in New Issue
Block a user