Locale::getEnglish(),
1,
"1");
+
+ assertFormatSingle(
+ u"Hide If Whole with Rounding Mode A (ICU-21881)",
+ u".00/w rounding-mode-floor",
+ u".00/w rounding-mode-floor",
+ NumberFormatter::with().precision(Precision::fixedFraction(2)
+ .trailingZeroDisplay(UNUM_TRAILING_ZERO_HIDE_IF_WHOLE))
+ .roundingMode(UNUM_ROUND_FLOOR),
+ Locale::getEnglish(),
+ 3.009,
+ "3");
+
+ assertFormatSingle(
+ u"Hide If Whole with Rounding Mode B (ICU-21881)",
+ u".00/w rounding-mode-half-up",
+ u".00/w rounding-mode-half-up",
+ NumberFormatter::with().precision(Precision::fixedFraction(2)
+ .trailingZeroDisplay(UNUM_TRAILING_ZERO_HIDE_IF_WHOLE))
+ .roundingMode(UNUM_ROUND_HALFUP),
+ Locale::getEnglish(),
+ 3.001,
+ "3");
}
void NumberFormatterApiTest::roundingFigures() {
/** Package-private clone method */
abstract Precision createCopy();
+ /**
+ * Call this function to copy the fields from the Precision base class.
+ *
+ * Note: It would be nice if this returned the copy, but most impls return the child class, not Precision.
+ */
+ /* package-private */ void createCopyHelper(Precision copy) {
+ copy.mathContext = mathContext;
+ copy.trailingZeroDisplay = trailingZeroDisplay;
+ }
+
/**
* @internal
* @deprecated ICU 60 This API is ICU internal only.
@Override
BogusRounder createCopy() {
BogusRounder copy = new BogusRounder();
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
@Deprecated
public Precision into(Precision precision) {
Precision copy = precision.createCopy();
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
@Override
InfiniteRounderImpl createCopy() {
InfiniteRounderImpl copy = new InfiniteRounderImpl();
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
@Override
FractionRounderImpl createCopy() {
FractionRounderImpl copy = new FractionRounderImpl(minFrac, maxFrac);
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
@Override
SignificantRounderImpl createCopy() {
SignificantRounderImpl copy = new SignificantRounderImpl(minSig, maxSig);
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
@Override
FracSigRounderImpl createCopy() {
FracSigRounderImpl copy = new FracSigRounderImpl(minFrac, maxFrac, minSig, maxSig, priority, retain);
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
@Override
IncrementRounderImpl createCopy() {
IncrementRounderImpl copy = new IncrementRounderImpl(increment);
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
@Override
IncrementOneRounderImpl createCopy() {
IncrementOneRounderImpl copy = new IncrementOneRounderImpl(increment, minFrac, maxFrac);
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
@Override
IncrementFiveRounderImpl createCopy() {
IncrementFiveRounderImpl copy = new IncrementFiveRounderImpl(increment, minFrac, maxFrac);
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
@Override
CurrencyRounderImpl createCopy() {
CurrencyRounderImpl copy = new CurrencyRounderImpl(usage);
- copy.mathContext = mathContext;
+ createCopyHelper(copy);
return copy;
}
}
ULocale.ENGLISH,
1,
"1");
+
+ assertFormatSingle(
+ "Hide If Whole with Rounding Mode A (ICU-21881)",
+ ".00/w rounding-mode-floor",
+ ".00/w rounding-mode-floor",
+ NumberFormatter.with().precision(Precision.fixedFraction(2)
+ .trailingZeroDisplay(TrailingZeroDisplay.HIDE_IF_WHOLE))
+ .roundingMode(RoundingMode.FLOOR),
+ ULocale.ENGLISH,
+ 3.009,
+ "3");
+
+ assertFormatSingle(
+ "Hide If Whole with Rounding Mode B (ICU-21881)",
+ ".00/w rounding-mode-half-up",
+ ".00/w rounding-mode-half-up",
+ NumberFormatter.with().precision(Precision.fixedFraction(2)
+ .trailingZeroDisplay(TrailingZeroDisplay.HIDE_IF_WHOLE))
+ .roundingMode(RoundingMode.HALF_UP),
+ ULocale.ENGLISH,
+ 3.001,
+ "3");
}
@Test