From c3b36d24c1a9e8536f4907691c263bebb7b8a67f Mon Sep 17 00:00:00 2001 From: Emiyare Ikwut-Ukwa Date: Tue, 20 Aug 2024 22:29:03 +0000 Subject: [PATCH] CLDR-11018 currency decimal place isn't accurate in the examples See #3975 --- .../unicode/cldr/test/ExampleGenerator.java | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java index 913e4884462..bb8fcf2c7f5 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java @@ -1,34 +1,5 @@ package org.unicode.cldr.test; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableList; -import com.ibm.icu.impl.Row.R3; -import com.ibm.icu.impl.Utility; -import com.ibm.icu.impl.number.DecimalQuantity; -import com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD; -import com.ibm.icu.lang.UCharacter; -import com.ibm.icu.text.BreakIterator; -import com.ibm.icu.text.DateFormat; -import com.ibm.icu.text.DateFormatSymbols; -import com.ibm.icu.text.DateTimePatternGenerator; -import com.ibm.icu.text.DecimalFormat; -import com.ibm.icu.text.DecimalFormatSymbols; -import com.ibm.icu.text.ListFormatter; -import com.ibm.icu.text.MessageFormat; -import com.ibm.icu.text.NumberFormat; -import com.ibm.icu.text.PluralRules; -import com.ibm.icu.text.PluralRules.DecimalQuantitySamples; -import com.ibm.icu.text.PluralRules.DecimalQuantitySamplesRange; -import com.ibm.icu.text.PluralRules.Operand; -import com.ibm.icu.text.PluralRules.SampleType; -import com.ibm.icu.text.SimpleDateFormat; -import com.ibm.icu.text.SimpleFormatter; -import com.ibm.icu.text.UTF16; -import com.ibm.icu.text.UnicodeSet; -import com.ibm.icu.util.Calendar; -import com.ibm.icu.util.Output; -import com.ibm.icu.util.TimeZone; -import com.ibm.icu.util.ULocale; import java.io.PrintWriter; import java.io.StringWriter; import java.text.ChoiceFormat; @@ -47,6 +18,7 @@ import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; + import org.unicode.cldr.tool.LikelySubtags; import org.unicode.cldr.util.AnnotationUtil; import org.unicode.cldr.util.CLDRConfig; @@ -75,6 +47,7 @@ import org.unicode.cldr.util.ScriptToExemplars; import org.unicode.cldr.util.SimpleUnicodeSetFormatter; import org.unicode.cldr.util.SupplementalDataInfo; +import org.unicode.cldr.util.SupplementalDataInfo.CurrencyNumberInfo; import org.unicode.cldr.util.SupplementalDataInfo.PluralInfo; import org.unicode.cldr.util.SupplementalDataInfo.PluralInfo.Count; import org.unicode.cldr.util.SupplementalDataInfo.PluralType; @@ -91,6 +64,36 @@ import org.unicode.cldr.util.personname.PersonNameFormatter.NamePattern; import org.unicode.cldr.util.personname.SimpleNameObject; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; +import com.ibm.icu.impl.Row.R3; +import com.ibm.icu.impl.Utility; +import com.ibm.icu.impl.number.DecimalQuantity; +import com.ibm.icu.impl.number.DecimalQuantity_DualStorageBCD; +import com.ibm.icu.lang.UCharacter; +import com.ibm.icu.text.BreakIterator; +import com.ibm.icu.text.DateFormat; +import com.ibm.icu.text.DateFormatSymbols; +import com.ibm.icu.text.DateTimePatternGenerator; +import com.ibm.icu.text.DecimalFormat; +import com.ibm.icu.text.DecimalFormatSymbols; +import com.ibm.icu.text.ListFormatter; +import com.ibm.icu.text.MessageFormat; +import com.ibm.icu.text.NumberFormat; +import com.ibm.icu.text.PluralRules; +import com.ibm.icu.text.PluralRules.DecimalQuantitySamples; +import com.ibm.icu.text.PluralRules.DecimalQuantitySamplesRange; +import com.ibm.icu.text.PluralRules.Operand; +import com.ibm.icu.text.PluralRules.SampleType; +import com.ibm.icu.text.SimpleDateFormat; +import com.ibm.icu.text.SimpleFormatter; +import com.ibm.icu.text.UTF16; +import com.ibm.icu.text.UnicodeSet; +import com.ibm.icu.util.Calendar; +import com.ibm.icu.util.Output; +import com.ibm.icu.util.TimeZone; +import com.ibm.icu.util.ULocale; + /** * Class to generate examples and help messages for the Survey tool (or console version). * @@ -2685,6 +2688,13 @@ private String handleCurrencyFormat(XPathParts parts, String value, boolean show icuServiceBuilder.getCurrencyFormat(currency, currencySymbol, numberSystem); df.applyPattern(value); + // getCurrencyFormat sets digits, but applyPattern seems to overwrite it, so fix it again here + SupplementalDataInfo supplementalData = CONFIG.getSupplementalDataInfo(); + CurrencyNumberInfo info = supplementalData.getCurrencyNumberInfo(currency); + int digits = info.getDigits(); + df.setMinimumFractionDigits(digits); + df.setMaximumFractionDigits(digits); + String countValue = parts.getAttributeValue(-1, "count"); if (countValue != null) { return formatCountDecimal(df, countValue);