mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-20 20:19:32 +00:00
Adopt new algorithm for trailing zeros in rounding priority
This commit is contained in:
parent
3654e945b6
commit
25af8b5e92
2 changed files with 26 additions and 11 deletions
|
@ -483,18 +483,10 @@ void RoundingImpl::apply(impl::DecimalQuantity &value, UErrorCode& status) const
|
|||
// withMinDigits + withMaxDigits
|
||||
displayMag = uprv_min(displayMag1, displayMag2);
|
||||
} else if (fPrecision.fUnion.fracSig.fPriority == UNUM_ROUNDING_PRIORITY_RELAXED) {
|
||||
if (roundingMag2 <= roundingMag1) {
|
||||
displayMag = displayMag2;
|
||||
} else {
|
||||
displayMag = displayMag1;
|
||||
}
|
||||
displayMag = uprv_min(displayMag1, displayMag2);
|
||||
} else {
|
||||
U_ASSERT(fPrecision.fUnion.fracSig.fPriority == UNUM_ROUNDING_PRIORITY_STRICT);
|
||||
if (roundingMag2 <= roundingMag1) {
|
||||
displayMag = displayMag1;
|
||||
} else {
|
||||
displayMag = displayMag2;
|
||||
}
|
||||
displayMag = uprv_max(displayMag1, displayMag2);
|
||||
}
|
||||
resolvedMinFraction = uprv_max(0, -displayMag);
|
||||
|
||||
|
|
|
@ -3386,6 +3386,7 @@ void NumberFormatterApiTest::roundingFractionFigures() {
|
|||
u"0",
|
||||
u"0");
|
||||
|
||||
// Keep the result having more trailing zeros
|
||||
assertFormatSingle(
|
||||
u"FracSig withSignificantDigits Trailing Zeros RELAXED",
|
||||
u".0/@@@r",
|
||||
|
@ -3396,7 +3397,7 @@ void NumberFormatterApiTest::roundingFractionFigures() {
|
|||
1,
|
||||
u"1.00");
|
||||
|
||||
// Trailing zeros follow the strategy that was chosen:
|
||||
// Keep the result having fewer trailing zeros
|
||||
assertFormatSingle(
|
||||
u"FracSig withSignificantDigits Trailing Zeros STRICT",
|
||||
u".0/@@@s",
|
||||
|
@ -3407,6 +3408,28 @@ void NumberFormatterApiTest::roundingFractionFigures() {
|
|||
1,
|
||||
u"1.0");
|
||||
|
||||
// Keep the result having more trailing zeros
|
||||
assertFormatSingle(
|
||||
u"FracSig withSignificantDigits Trailing Zeros RELAXED",
|
||||
u".00#/@@####r",
|
||||
u".00#/@@####r",
|
||||
NumberFormatter::with().precision(Precision::minMaxFraction(2, 3)
|
||||
.withSignificantDigits(2, 6, UNUM_ROUNDING_PRIORITY_RELAXED)),
|
||||
Locale::getEnglish(),
|
||||
1,
|
||||
u"1.00");
|
||||
|
||||
// Keep the result having fewer trailing zeros
|
||||
assertFormatSingle(
|
||||
u"FracSig withSignificantDigits Trailing Zeros STRICT",
|
||||
u".00#/@@####s",
|
||||
u".00#/@@####s",
|
||||
NumberFormatter::with().precision(Precision::minMaxFraction(2, 3)
|
||||
.withSignificantDigits(2, 6, UNUM_ROUNDING_PRIORITY_STRICT)),
|
||||
Locale::getEnglish(),
|
||||
1,
|
||||
u"1.0");
|
||||
|
||||
assertFormatSingle(
|
||||
u"FracSig withSignificantDigits at rounding boundary",
|
||||
u"precision-integer/@@@s",
|
||||
|
|
Loading…
Add table
Reference in a new issue