Skip to content

Add Intl.NumberFormat tests for significant-digit rounding into the next magnitude - #5124

Open
jessealama wants to merge 4 commits into
tc39:mainfrom
jessealama:numberformat-significant-digits-rollover
Open

Add Intl.NumberFormat tests for significant-digit rounding into the next magnitude#5124
jessealama wants to merge 4 commits into
tc39:mainfrom
jessealama:numberformat-significant-digits-rollover

Conversation

@jessealama

@jessealama jessealama commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Depends on #5126; the first two commits here are from that PR and will
drop out once it merges.

Add tests for Intl.NumberFormat when rounding to a fixed number of significant digits carries into a new leading digit, e.g. 9.999 at three significant digits (should round to 10 rather than 9.99). As far as I can see, we don't have tests where the rounded value has a different order of magnitude from the input.

I've added tests for a few locales & numbering systems outside of en-US/latn.

The format test covers different branches of ToRawPrecision where we might conceivably place digits in different slots. We also test the interaction with trailing-zero trimming, and values just below the rounding boundary that must not roll over, given the significant digit settings in the formatter. The formatToParts test checks that grouping separators and decimal parts follow the rounded magnitude.

This work arose in the process of working on the Amount proposal and its polyfill, where I noticed that some behavior I was relying on didn't seem to have test262 coverage. tc39/ecma402#572 is the spec fix whose behavior we're nailing down here.

Spec: https://tc39.es/ecma402/#sec-torawprecision

@jessealama
jessealama requested a review from a team as a code owner September 2, 2026 07:53
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

11 new or modified tests were run on 7 engines.

View workflow run

Test Engine262 GraalJS JavaScriptCore QuickJS SpiderMonkey V8 XS
intl402/Collator/ignore-invalid-unicode-ext-values.js
intl402/Collator/numeric-and-caseFirst.js
intl402/DateTimeFormat/casing-numbering-system-calendar-options.js
intl402/DateTimeFormat/numbering-system-calendar-options.js
intl402/DateTimeFormat/prototype/resolvedOptions/resolved-locale-with-hc-unicode.js
intl402/NumberFormat/casing-numbering-system-options.js
intl402/NumberFormat/numbering-system-options.js
intl402/NumberFormat/prototype/format/format-significant-digits-rounding-magnitude.js
intl402/NumberFormat/prototype/formatToParts/significant-digits-rounding-magnitude-en-US.js
intl402/NumberFormat/test-option-currency.js
intl402/NumberFormat/throws-for-currency-style-without-currency-option.js

@jessealama
jessealama force-pushed the numberformat-significant-digits-rollover branch from 8d538a0 to 3590a62 Compare September 2, 2026 15:33
…cale

The Collator test for ignored invalid extension values now builds its
baseline collator from the base name as well, so that its resolved-locale
and resolved-options comparisons use the same locale as the collators
under test.
@jessealama
jessealama force-pushed the numberformat-significant-digits-rollover branch from 3590a62 to 7565dbb Compare September 6, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants