-
-
Notifications
You must be signed in to change notification settings - Fork 36
Design document for percent formatting #1068
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
base: main
Are you sure you want to change the base?
Conversation
This document is focused for now on documenting the options.
Co-authored-by: Mark Davis <[email protected]>
I just realised that this whole discussion is also related to #1015 (review), which we probably ought to address as well. In other words, as we currently don't have |
Co-authored-by: Eemeli Aro <[email protected]>
Co-authored-by: Eemeli Aro <[email protected]>
In the 2025-05-05 call, we agreed to remove the proposed design so that we can commit the design document to the main line in the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without an explicit proposed design, I have no objections to merging this. I've added a couple of comments inline, along with typo-ish corrections.
Co-authored-by: Eemeli Aro <[email protected]>
Co-authored-by: Eemeli Aro <[email protected]>
Co-authored-by: Eemeli Aro <[email protected]>
In our most recent call, we discussed adopting the proposed design found in this commit. Note the addition of selector behavior.
- REQUIRE the `:number` and `:integer` functions to support `style=percent` as an option | ||
- The functions `:number` and `:integer` scale the operand, e.g. `{5 :integer style=percent}` formats as `500%`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find :integer style=percent
to be confusing, and I don't think we should support it. Even though it may be well specified, it's not obvious to a reader whether the scaling happens before the rounding, or after it. We should avoid introducing unnecessary uncertainty, esp. as it's likely that implementations will choose to default to maximumFractionDigits=0
for percent formatting.
Already now, the options supported by :integer
are a subset of the options supported by :number
, so this would only extend the set of excluded options.
- REQUIRE the `:number` and `:integer` functions to support `style=percent` as an option | |
- The functions `:number` and `:integer` scale the operand, e.g. `{5 :integer style=percent}` formats as `500%`. | |
- REQUIRE the `:number` function to support `style=percent` as an option | |
- The function `:number` scales the operand, e.g. `{5 :number style=percent}` formats as `500%`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. In this commit I was trying to capture the WG telecon conversation and I understood it to include :integer
.
I don't think :integer style=percent
is confusing, but it does add more surface to number formatting. Do I suppose correctly that you'd oppose adding other stylistic options (compact, scientific, etc.) to :integer
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, yes. I don't want to commit to the position prematurely, but it'd be my starting point to be a bit queasy about needing to think about whether 4.2e2
is really an "integer" or not.
Note that the selector selects on the scaled value | ||
(selectors currently cannot select fractional parts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Highlighting for @sffc and @ryzokuken that this may require supporting something like style
as an Intl.PluralRules option, or being ok with Intl.MessageFormat offering a capability beyond Intl.PluralRules.
Is plural category selection on percent-formatted values already well supported by the ICU libraries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if selection makes sense for :number style=percent
, is there a reason to not allow selection for :unit unit=percent
as well? And if the latter is fine, then why not allow selection for all of :unit
.
My preference would be for us to not allow for selection with percent formatting at this time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may require supporting something like style as an Intl.PluralRules option
I don't think this necessarily follows? The function handler would scale the value before using plural rules, just as the function handler calls Intl.NumberFormat
to format the number later.
My preference would be for us to not allow for selection with percent formatting at this time.
This would require a separate placeholder just to perform message selection on what is fundamentally a number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may require supporting something like style as an Intl.PluralRules option
I don't think this necessarily follows? The function handler would scale the value before using plural rules, just as the function handler calls
Intl.NumberFormat
to format the number later.
Quite recently in tc39/ecma402#989 we added notation
as one of the Intl.PluralRules
options. It would therefore be a bit surprising to effectively support style=percent
for selection scaling in Intl.MessageFormat, but not for Intl.PluralRules
.
My preference would be for us to not allow for selection with percent formatting at this time.
This would require a separate placeholder just to perform message selection on what is fundamentally a number.
Does your position generalise to preferring selection to work on all :unit
values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does your position generalise to preferring selection to work on all :unit values?
I'm not sure. I think it might, at least in terms of exact selection. Plural rules don't work well/aren't needed (what's actually wanted is more like inflection). But there are plenty of cases where one might want a specific value to produce a specific message, with 0
being the most common case.
A lot of unit selection cases actually look like what ChoiceFormat
is good at: separating messages above/below a given threshold, e.g. switching from kilometers to meters (or miles to feet) in driving directions at some cutoff.
> Examples. These are equivalent **except** that `:unit` does NOT scale. | ||
>``` | ||
> {{You have {$pct :number style=percent} remaining.}} | ||
> {{You have {$pct :unit unit=percent} remaining.}} | ||
> {{You have {$pct :integer style=percent} remaining.}} | ||
>``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> Examples. These are equivalent **except** that `:unit` does NOT scale. | |
>``` | |
> {{You have {$pct :number style=percent} remaining.}} | |
> {{You have {$pct :unit unit=percent} remaining.}} | |
> {{You have {$pct :integer style=percent} remaining.}} | |
>``` | |
> Examples. These are equivalent **except** that `:unit` does NOT scale. | |
>``` | |
> {{You have {$pct :number style=percent} remaining.}} | |
> {{You have {$scaledPct :unit unit=percent} remaining.}} | |
>``` |
@@ -0,0 +1,389 @@ | |||
# Formatting Percent Values | |||
|
|||
Status: **Proposed** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this PR is intended to close #956, then we should not be landing this document with just "Proposed" status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that we will choose a design before committing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not happy with the Proposed Design: Let's not add the style
option back to :number
. It was productive when we removed it, and I don't want to go back. Among other things, it causes problems when mixed with other options, questionable plural selection behavior as @eemeli noted, and inconsistent with Intl.NumberFormat which uses style
for currency and unit as well.
I also do not like requiring :unit unit=percent
, because we want percent formatting to not pull in all unit formatting data, but this is unavoidable in this design for reasons the ICU4X TC has expressed previously.
|
||
## Constraints | ||
|
||
_What prior decisions and existing conditions limit the possible design?_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should mention that since MF1 scales, we want MF2 to be able to scale?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't necessarily want MF2 to scale. There is a hot debate about whether scaling or non-scaling is preferred.
_Cons_ | ||
- Adds to a (growing) list of functions | ||
- Not "special enough" to warrant its own formatter? | ||
- Unlike `:currency`, because currency formatting depends on currency codes, | ||
which in turn impact default fraction digits, and other presentation details. | ||
Nothing like that applies to percents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't buy any of these cons.
- There is no set of rules I've seen to dictate when or when not to add new functions. Apparently we are okay with
:integer
and:number
being separate even though one is a superset of another. And we seem to have been okay with:date
,:time
, and:datetime
being different. So I don't think "we don't want to grow the list of functions" is sufficient justification to not add this function. - This document is self-contradictory in percent formatting being "important enough". Apparently the author thinks that it is "important enough" to muddy
:number
by adding back thestyle=percent
option, and that it is important enough to make:unit unit=percent
be REQUIRED. - We have evidence of at least one option being different, a potential
scaling
option. But, besides this, I point back to:integer
which is just a subset of:number
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no set of rules I've seen to dictate when or when not to add new functions. Apparently we are okay with :integer and :number being separate even though one is a superset of another. And we seem to have been okay with :date, :time, and :datetime being different. So I don't think "we don't want to grow the list of functions" is sufficient justification to not add this function.
In the call (and elsewhere), we discussed that :integer
is a convenience function for :number
(specifically a shorthand for {$n :number maximumFractionDigits=0}
. The question is whether we are "splitters" or "lumpers" for functions, that is, whether we prefer a single function with lots of options or many functions with few(er) options.
I called out in the call that there is no rhyme nor reason to our current policy.
Apparently the author thinks that it is "important enough" to muddy :number by adding back the style=percent option, and that it is important enough to make :unit unit=percent be REQUIRED.
The author is recording what the WG wanted recorded. (In fact, the author does not agree with this design)
(chair hat OFF) Adding
I'm not opposed to adding convenience functions. I think Alternatively we could regard
I think My preferred solution is:
(chair hat ON) I observe that we're not closing on a design. If we do not achieve consensus on a design in the next (2025-06-02) call, I will call for a ballot. |
This document now includes the proposed design discussed in the (poorly documented, sparsely attended) 2025-05-19 call. The emerging consensus appears to be:
:number
/:integer
with optionstyle=percent
(this is the current design) with scaling:unit
with unitpercent
is REQUIRED but other units are not required, this function has NO scalingThe most recent commit posits that
:number
/:integer
select after scaling because we don't support fraction selection currently.Note
All previous conversations were marked resolved on purpose and not because their content was in any way deficient, off topic, or necessarily addressed. Please comment on the proposed design.