Skip to content

fix(@formatjs/intl-numberformat): handle massive numbers, fix #4236#5782

Closed
longlho wants to merge 1 commit intomainfrom
01-01-fix_formatjs_intl-numberformat_handle_massive_numbers_fix_4236
Closed

fix(@formatjs/intl-numberformat): handle massive numbers, fix #4236#5782
longlho wants to merge 1 commit intomainfrom
01-01-fix_formatjs_intl-numberformat_handle_massive_numbers_fix_4236

Conversation

@longlho
Copy link
Member

@longlho longlho commented Jan 2, 2026

TL;DR

Fix compact number formatting for very large numbers that exceed available locale patterns.

What changed?

  • Modified ComputeExponentForMagnitude to correctly calculate the exponent when a number exceeds the maximum threshold
  • Updated getCompactDisplayPattern to use the largest available pattern when formatting numbers that exceed the available magnitude patterns
  • Added fallback logic for both currency and non-currency compact formatting

How to test?

Run the new test cases that verify compact notation works correctly with very large numbers:

  • Verify that numbers like 1 trillion (1e12) format as "1T"
  • Verify that numbers exceeding 1000 trillion (1e15) format correctly using the largest available pattern (e.g., "1000T")
  • Verify that even larger numbers (e.g., 10 quadrillion) continue to use the appropriate suffix

Why make this change?

Fixes issue #4236 where very large numbers (greater than 1000 trillion) were not formatting correctly with compact notation. Previously, when a number exceeded the largest available threshold in locale data, the formatting would fail to apply the correct exponent calculation. This change ensures that even numbers beyond the explicit thresholds in locale data are formatted consistently using the largest available pattern.

@longlho longlho marked this pull request as ready for review January 2, 2026 03:35
@graphite-app
Copy link

graphite-app bot commented Jan 2, 2026

Merge activity

  • Jan 2, 3:38 AM UTC: longlho added this pull request to the Graphite merge queue.
  • Jan 2, 3:39 AM UTC: CI is running for this pull request on a draft pull request (#5783) due to your merge queue CI optimization settings.
  • Jan 2, 3:42 AM UTC: Merged by the Graphite merge queue via draft PR: #5783.

graphite-app bot pushed a commit that referenced this pull request Jan 2, 2026
…5782)

### TL;DR

Fix compact number formatting for very large numbers that exceed available locale patterns.

### What changed?

- Modified `ComputeExponentForMagnitude` to correctly calculate the exponent when a number exceeds the maximum threshold
- Updated `getCompactDisplayPattern` to use the largest available pattern when formatting numbers that exceed the available magnitude patterns
- Added fallback logic for both currency and non-currency compact formatting

### How to test?

Run the new test cases that verify compact notation works correctly with very large numbers:
- Verify that numbers like 1 trillion (1e12) format as "1T"
- Verify that numbers exceeding 1000 trillion (1e15) format correctly using the largest available pattern (e.g., "1000T")
- Verify that even larger numbers (e.g., 10 quadrillion) continue to use the appropriate suffix

### Why make this change?

Fixes issue #4236 where very large numbers (greater than 1000 trillion) were not formatting correctly with compact notation. Previously, when a number exceeded the largest available threshold in locale data, the formatting would fail to apply the correct exponent calculation. This change ensures that even numbers beyond the explicit thresholds in locale data are formatted consistently using the largest available pattern.
@graphite-app graphite-app bot closed this Jan 2, 2026
@graphite-app graphite-app bot deleted the 01-01-fix_formatjs_intl-numberformat_handle_massive_numbers_fix_4236 branch January 2, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant