U_ASSERT(minInt >= 0);
U_ASSERT(maxInt >= minInt);
+ // Special behavior: do not set minInt to be less than what is already set.
+ // This is so significant digits rounding can set the integer length.
+ if (minInt < lReqPos) {
+ minInt = lReqPos;
+ }
+
// Save values into internal state
// Negation is safe for minFrac/maxFrac because -Integer.MAX_VALUE > Integer.MIN_VALUE
lOptPos = maxInt;
value.setFractionLength(
uprv_max(0, -getDisplayMagnitudeSignificant(value, fUnion.fracSig.fMinSig)),
INT32_MAX);
+ // Make sure that digits are displayed on zero.
+ if (value.isZero() && fUnion.fracSig.fMinSig > 0) {
+ value.setIntegerLength(1, INT32_MAX);
+ }
break;
case RND_FRACTION_SIGNIFICANT: {
Locale::getEnglish(),
9.99999,
u"10.0");
+
+ assertFormatSingle(
+ u"Fixed Significant on zero with lots of integer width",
+ u"@ integer-width/+000",
+ NumberFormatter::with().rounding(Rounder::fixedDigits(1))
+ .integerWidth(IntegerWidth::zeroFillTo(3)),
+ Locale::getEnglish(),
+ 0,
+ "000");
+
+ assertFormatSingle(
+ u"Fixed Significant on zero with zero integer width",
+ u"@ integer-width/+",
+ NumberFormatter::with().rounding(Rounder::fixedDigits(1))
+ .integerWidth(IntegerWidth::zeroFillTo(0)),
+ Locale::getEnglish(),
+ 0,
+ "0");
}
void NumberFormatterApiTest::roundingFractionFigures() {
assert minInt >= 0;
assert maxInt >= minInt;
+ // Special behavior: do not set minInt to be less than what is already set.
+ // This is so significant digits rounding can set the integer length.
+ if (minInt < lReqPos) {
+ minInt = lReqPos;
+ }
+
// Save values into internal state
// Negation is safe for minFrac/maxFrac because -Integer.MAX_VALUE > Integer.MIN_VALUE
lOptPos = maxInt;
value.roundToMagnitude(getRoundingMagnitudeSignificant(value, maxSig), mathContext);
value.setFractionLength(Math.max(0, -getDisplayMagnitudeSignificant(value, minSig)),
Integer.MAX_VALUE);
+ // Make sure that digits are displayed on zero.
+ if (value.isZero() && minSig > 0) {
+ value.setIntegerLength(1, Integer.MAX_VALUE);
+ }
}
/**
ULocale.ENGLISH,
9.99999,
"10.0");
+
+ assertFormatSingle(
+ "Fixed Significant on zero with zero integer width",
+ "@ integer-width/+",
+ NumberFormatter.with().rounding(Rounder.fixedDigits(1)).integerWidth(IntegerWidth.zeroFillTo(0)),
+ ULocale.ENGLISH,
+ 0,
+ "0");
+
+ assertFormatSingle(
+ "Fixed Significant on zero with lots of integer width",
+ "@ integer-width/+000",
+ NumberFormatter.with().rounding(Rounder.fixedDigits(1)).integerWidth(IntegerWidth.zeroFillTo(3)),
+ ULocale.ENGLISH,
+ 0,
+ "000");
}
@Test