int32_t sigDigits = precision();
if (sigDigits > 0) {
adjustedNum.round(sigDigits);
+ // Travis Keep (21/2/2014): Calling round on a digitList does not necessarily
+ // preserve the sign of that digit list. Preserving the sign is especially
+ // important when formatting -0.0 for instance. Not preserving the sign seems
+ // like a bug because I cannot think of any case where the sign would actually
+ // have to change when rounding. For now, we preserve the sign by setting the
+ // positive attribute directly.
+ adjustedNum.setPositive(!isNegative);
}
} else {
// Fixed point format. Round to a set number of fraction digits.
TESTCASE_AUTO(Test10419RoundingWith0FractionDigits);
TESTCASE_AUTO(Test10468ApplyPattern);
TESTCASE_AUTO(TestRoundingScientific10542);
+ TESTCASE_AUTO(TestZeroScientific10547);
TESTCASE_AUTO_END;
}
}
}
+void NumberFormatTest::TestZeroScientific10547() {
+ UErrorCode status = U_ZERO_ERROR;
+ {
+ DecimalFormat fmt("0.00", status);
+ UnicodeString out;
+ fmt.format(-0.0, out);
+ assertEquals("formatFixed", "-0.00", out);
+ }
+ DecimalFormat fmt("0.00E0", status);
+ if (!assertSuccess("Formt creation", status)) {
+ return;
+ }
+ UnicodeString out;
+ fmt.format(-0.0, out);
+ assertEquals("format", "-0.00E0", out);
+}
+
void NumberFormatTest::verifyRounding(
DecimalFormat& format,
const double *values,
/************************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2013, International Business Machines Corporation
+ * Copyright (c) 1997-2014, International Business Machines Corporation
* and others. All Rights Reserved.
************************************************************************/
void Test10419RoundingWith0FractionDigits();
void Test10468ApplyPattern();
void TestRoundingScientific10542();
+ void TestZeroScientific10547();
private:
UBool testFormattableAsUFormattable(const char *file, int line, Formattable &f);