UPDATE: This API is available in ICU 63.
C++:
http://icu-project.org/apiref/icu4c/numberrangeformatter_8h.html
Java:
http://icu-project.org/apiref/icu4c/classicu_1_1number_1_1NumberRangeFormatter.html
—
Split from
We've gotten a request for formatting currencies with ranges, eg
$1.23-2.57
At a minimum, we need to provide access to the range pattern (eg for English, `"{0}–{1}"`). That would allow people to produce patterns like $1.23-$2.47, or with some more work, like the above.
Related: #10994
Related: #10985
Possible API:
where `Range` extends `Number`. I like this option because it means easy integration with MessageFormat.
We can provide one overload for API users who don't want to create a Range object:
The range style can be encoded into a two-dimensional enum:
| = Standard = | = Collapse = | ||
---|---|---|---|---|
| = Range(3, 5) = | = Range(5, 5) = | = Range(3, 5) = | = Range(5, 5) = |
= Narrow = | $3 – $5 | $5 | $3–5 | $5 |
= Short = | $3 – $5 | ~$5 | $3–5 | ~$5 |
= Safe = | $3 – $5 | null | $3–5 | null |
The enum itself can look like this:
and it can be fed as an option like this:
Comments?
The two axes could reasonably be taken as two separate orthogonal settings.
and then
Or, they could be one option with nested settings, similar to Precision and Notation:
This API has been proposed and accepted.