Skip to content

fix(intl): implement percent style for Intl.NumberFormat#5257

Closed
rubys wants to merge 1 commit intoboa-dev:mainfrom
rubys:fix-intl-numberformat-percent
Closed

fix(intl): implement percent style for Intl.NumberFormat#5257
rubys wants to merge 1 commit intoboa-dev:mainfrom
rubys:fix-intl-numberformat-percent

Conversation

@rubys
Copy link

@rubys rubys commented Mar 25, 2026

Summary

Closes #5246.

  • Multiply input by 100 (multiply_pow10(2)) for style: "percent" per ECMA-402 FormatNumeric
  • Append percent sign to the formatted output via new format_to_js_string() helper
  • Update all three call sites (NumberFormat.format, Number.toLocaleString, BigInt.toLocaleString) to use the new helper

Known limitation

The percent sign is currently appended with a narrow no-break space (U+202F) uniformly across all locales. This is correct for most locales (e.g., French "50 %", German "50 %"), but some locales (e.g., English) conventionally use no space ("50%"). The proper fix requires locale-aware percent formatting from ICU4X (see icu4x#4483). Once PercentFormatter is available upstream, this workaround should be replaced.

Test262 conformance (test/intl402/NumberFormat)

Test result main PR difference
Passed 132 133 +1
Ignored 0 0 0
Failed 121 120 -1
Panics 0 0 0

Fixed tests (1):

  • test/prototype/format/percent-formatter.js (previously Failed)

No regressions.

Test plan

  • cargo test -p boa_engine --features intl_bundled -- number_format — all 4 tests pass
  • cargo test -p boa_engine --features intl_bundled -- to_locale_string — existing tests unaffected
  • cargo clippy --all-features --all-targets — no warnings
  • cargo fmt -- --check — clean
  • boa_tester against test/intl402/NumberFormat — +1 fixed, 0 broken

🤖 Generated with Claude Code

Multiply the input value by 100 and append a percent sign when
`style: "percent"` is used, matching the ECMA-402 spec. All three
call sites (NumberFormat.format, Number.toLocaleString,
BigInt.toLocaleString) now go through `format_to_js_string` so
that style-specific affixes are applied consistently.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rubys rubys requested review from a team, jedel1043 and nekevss as code owners March 25, 2026 23:13
@github-actions github-actions bot added Waiting On Review Waiting on reviews from the maintainers C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics C-Intl Changes related to the `Intl` implementation labels Mar 25, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 25, 2026
@github-actions
Copy link

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,732 50,733 +1
Ignored 1,426 1,426 0
Failed 805 804 -1
Panics 0 0 0
Conformance 95.79% 95.79% +0.00%
Fixed tests (1):
test/intl402/NumberFormat/prototype/format/percent-formatter.js (previously Failed)

Tested main commit: 2437b6704c4315f6ec8f0766bf229fba23e0e61e
Tested PR commit: 64953419b6defdd8553d4e0797011e8463981445
Compare commits: 2437b67...6495341

@codecov
Copy link

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 59.87%. Comparing base (6ddc2b4) to head (6495341).
⚠️ Report is 919 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/builtins/bigint/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5257       +/-   ##
===========================================
+ Coverage   47.24%   59.87%   +12.63%     
===========================================
  Files         476      589      +113     
  Lines       46892    63415    +16523     
===========================================
+ Hits        22154    37970    +15816     
- Misses      24738    25445      +707     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jedel1043
Copy link
Member

As we've mentioned in other PRs, we prefer to wait for the required i18n APIs to be available from ICU4X instead of hacking around its limitations

@jedel1043 jedel1043 closed this Mar 26, 2026
@github-actions github-actions bot removed the Waiting On Review Waiting on reviews from the maintainers label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Builtins PRs and Issues related to builtins/intrinsics C-Intl Changes related to the `Intl` implementation C-Tests Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intl.NumberFormat: Percent style is ignored (no multiplication or percent symbol)

2 participants