Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Intl.NumberFormat formatRange #393

Closed
sffc opened this issue Nov 27, 2019 · 7 comments
Closed

Add Intl.NumberFormat formatRange #393

sffc opened this issue Nov 27, 2019 · 7 comments
Assignees
Labels
c: numbers Component: numbers, currency, units Proposal Larger change requiring a proposal s: in progress Status: the issue has an active proposal

Comments

@sffc
Copy link
Contributor

sffc commented Nov 27, 2019

In the same vein as the Intl.DateTimeFormat.prototype.formatRange proposal, we should add a formatRange method to Intl.NumberFormat. We have clients who are requesting such a feature (google-internal link).

@sffc sffc added c: numbers Component: numbers, currency, units s: help wanted Status: help wanted; needs proposal champion labels Nov 27, 2019
@zbraniecki
Copy link
Member

Can you please make the request a bit more public? Motivation, use cases, reasons why it should be implemented by all browser engines and become part of the standard etc?

@sffc
Copy link
Contributor Author

sffc commented Nov 27, 2019

Example use cases:

  1. What Android versions are supported? 15-24 (standard number range)
  2. How much will your Uber ride cost in US? $10-$15 (currency range)
  3. How much will your Uber ride cost in Switzerland? 10-15 CHF (currency range with longer symbol)
  4. How long before your delivery arrives? 15-20 min (duration/unit range)

Why this belongs in the spec:

  1. Number range formatting is locale-sensitive and hard for programmers to get right; it is not sufficient to simply concatenate two numbers with a "-" in between
  2. A polyfill would have trouble implementing expectations like "$10-$15" repeating the currency symbol but "10-15 CHF" not repeating it; this is handled best in ICU internals
  3. Brings parity with Intl.DateTimeFormat.prototype.formatRange, meeting programmer expectations

@zbraniecki
Copy link
Member

Thank you!

this is handled best in ICU internals

Is that part of CLDR? How can we implement it in a non-ICU-specific fashion?

@sffc
Copy link
Contributor Author

sffc commented Nov 27, 2019

Thank you!

this is handled best in ICU internals

Is that part of CLDR? How can we implement it in a non-ICU-specific fashion?

Good question.

The CLDR spec does not specify the behavior of when to repeat the currency symbol or "collapse" it down. ICU currently performs a heuristic. I have an open bug to formalize ICU's heuristics into CLDR.

https://unicode-org.atlassian.net/browse/CLDR-11431

@sffc sffc added this to the ES 2021 milestone Mar 21, 2020
@sffc
Copy link
Contributor Author

sffc commented Mar 21, 2020

I plan to address this as part of my new proposal Intl.NumberFormat V3.

https://github.com/sffc/proposal-intl-numberformat-v3

@sffc sffc added s: in progress Status: the issue has an active proposal and removed s: help wanted Status: help wanted; needs proposal champion labels Mar 21, 2020
@sffc
Copy link
Contributor Author

sffc commented Apr 23, 2020

Question about which options to add for range formatting:

tc39/proposal-intl-numberformat-v3#6

@ben-allen
Copy link
Contributor

Closing as fixed when NumberFormat v3 landed 4257160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: numbers Component: numbers, currency, units Proposal Larger change requiring a proposal s: in progress Status: the issue has an active proposal
Projects
None yet
Development

No branches or pull requests

3 participants