Add Intl.NumberFormat formatRange
sffc opened this issue · 7 comments
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?
Example use cases:
- What Android versions are supported? 15-24 (standard number range)
- How much will your Uber ride cost in US? $10-$15 (currency range)
- How much will your Uber ride cost in Switzerland? 10-15 CHF (currency range with longer symbol)
- How long before your delivery arrives? 15-20 min (duration/unit range)
Why this belongs in the spec:
- 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
- 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
- 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?
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.
I plan to address this as part of my new proposal Intl.NumberFormat V3.
Question about which options to add for range formatting: