feat(experimental/dimension): Add cash formatting option to CurrencyFormatter#8175
Open
younies wants to merge 26 commits into
Open
feat(experimental/dimension): Add cash formatting option to CurrencyFormatter#8175younies wants to merge 26 commits into
younies wants to merge 26 commits into
Conversation
Implement the ValueRepresentation trait and Decimal marker struct. Migrate CurrencyFormatter to CurrencyFormatter<Decimal> with try_new_short and try_new_narrow constructors, removing the old non-generic try_new constructors. Update tests accordingly. TAG=agy CONV=0f8e0e91-077a-4704-b63f-0c02f37cbc41
- Update try_new_narrow and try_new_narrow_unstable to use robust fallback loading, ensuring consistency with short constructors and supporting numbering system overrides. - Add explanatory comments and TODOs for the manual constructors explaining the cross-crate dependency constraint. TAG=agy CONV=0f8e0e91-077a-4704-b63f-0c02f37cbc41
…sentation - Add TODO(unicode-org#8146) to format_fixed_decimal to track the discussion about whether FixedDecimal is the correct input type for currency formatting. TAG=agy CONV=0f8e0e91-077a-4704-b63f-0c02f37cbc41
- Remove test_en_us_aud to keep the test suite DRY, addressing reviewer feedback. CAD and USD tests already provide full coverage for the dollar currency prefix and narrow/short resolution logic. TAG=agy CONV=0f8e0e91-077a-4704-b63f-0c02f37cbc41
- Rename locale variable to prefs of type CurrencyFormatterPreferences across all test cases in format.rs for naming consistency and to address reviewer feedback. TAG=agy CONV=0f8e0e91-077a-4704-b63f-0c02f37cbc41
- Add test cases to test_numbering_system_override to verify that try_new_narrow correctly respects numbering system overrides (like ar-EG-u-nu-latn), ensuring consistency with try_new_short. - Rename short test variables for clarity. TAG=agy CONV=0f8e0e91-077a-4704-b63f-0c02f37cbc41
Revert manual precision additions to CurrencyEssentials and CurrencyExtendedData, and instead load and use the existing CurrencyFractionsV1 singleton to resolve currency precision. Also apply a fix to check_pattern in essentials provider to allow mismatches in grouping separators (Indian vs Western). TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
Introduce CurrencyPatternFractionsV1 marker to store precision extracted from CLDR currency patterns at datagen time. Update CurrencyFormatter and CompactCurrencyFormatter to load this data and implement a 3-step fallback for resolving currency precision: 1. Global currency-specific overrides (from CurrencyFractionsV1). 2. Locale-specific pattern precision (from CurrencyPatternFractionsV1). 3. Global default (2 decimals). TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
Update CurrencyFormatter to make CurrencyExtendedDataV1 (display names) optional. If the extended data for a currency is missing (e.g., for a fake or unsupported currency), we now fall back to using its ISO code as the display name, instead of failing construction. Add test_long_fallback_to_iso to verify this behavior. TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
Following the decision that Long formatting does not need locale-specific pattern precision fallback (as it has no pattern-defined precision and should fall back to the global default), we merge the pattern precision data (fractions_vec, standard_index, standard_next_to_alpha) directly into CurrencyEssentials. This optimizes Short and Narrow formatting by reducing the number of loaded data markers from 2 to 1, while Long formatting remains optimized by only loading CurrencyFractionsV1 (global overrides). Updates: - Removed CurrencyPatternFractionsV1 marker. - Added fractions_vec, standard_index, standard_next_to_alpha to CurrencyEssentials. - Updated datagen to populate these fields in CurrencyEssentialsV1. - Updated CurrencyFormatter and CompactCurrencyFormatter to use CurrencyEssentials for locale-specific precision. - Regenerated baked data. TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
- Pass CurrencyCode by value in CompactCurrencyFormatter::resolve_fraction_info. - Collapse nested if statements using Option::filter in resolve_fraction_info (both formatters). - Remove unused load_with_fallback from compact_formatter.rs. - Remove unused ZeroVec import from fractions.rs. - Remove unnecessary qualifications in essentials.rs (provider). - Remove needless borrow of locale in essentials.rs (provider). TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
This aligns the function name with its return type (FractionInfo) and makes it more descriptive of what it actually does. TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
Added comments in formatter.rs referencing UTS unicode-org#35 Section 3.11.1 explaining that we fall back to the currency code itself if the displayName is not found. TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
TAG=agy CONV=4e806c61-d22c-4821-8a7f-6c8e0ebb5a29
This was referenced Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the cash formatting option for
CurrencyFormatterandCompactCurrencyFormatter.Diff Base: #8169.
Changelog
Add
CurrencyUsageEnum:CurrencyUsageinoptions.rswithStandardandCashvariants.cash: booloption inCurrencyFormatterOptionswithusage: CurrencyUsage.Implement Cash Rounding Fallback:
resolve_fraction_infoin bothCurrencyFormatterandCompactCurrencyFormatterto check ifoptions.usageisCurrencyUsage::Cash.digitsandrounding) withcash_digitsandcash_roundingfrom the resolvedFractionInfo(if they are present in the data).Update Constructors:
CurrencyFormatterconstructors (try_new_short,try_new_narrow,try_new_longand their unstable variants) to acceptCurrencyFormatterOptionsso that callers can configure the usage.Tests:
Default::default()(which usesStandardusage).test_cash_roundinginformat.rsusingCHF(Swiss Franc) to verify thatCurrencyUsage::Cashcorrectly rounds values to the nearest 0.05 (e.g.,1.23->1.25,1.22->1.20) whileStandardusage keeps 2 decimal places (1.23and1.22).TAG=agy
CONV=f08dbbb0-24e0-4da6-a2f8-f6a19ba2c8b5