tc39/ecma402

Add Intl.NumberFormat formatRange

sffc opened this issue · 7 comments

sffc commented

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).

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 commented

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

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 commented

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 commented

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

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

sffc commented

Question about which options to add for range formatting:

tc39/proposal-intl-numberformat-v3#6

Closing as fixed when NumberFormat v3 landed 4257160