-
-
Notifications
You must be signed in to change notification settings - Fork 34
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 :percent
#988
base: main
Are you sure you want to change the base?
Add :percent
#988
Conversation
For the purposes of formatting, | ||
the numeric value of the _operand_ is multiplied by 100. |
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.
Since we have a separate function, purpose built for it, should we offer a pre-computed mode?
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.
You mean an option toggling if the input is multiplied or not?
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.
Yes, exactly.
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.
ICU4C calls it "scale" or "multiplier"
ICU4X calls it "multiply_pow10"
I don't think we've had a proper bikeshedding session on this before. I've sort-of named it what I felt like naming it and no one ever pushed back with better names.
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.
Given that we'll be defaulting to a value 1 getting formatted as something like "100%", I think scale
makes the most sense, with a default value of 1
and supporting 100
as an alternative. With this approach,
{42 :percent scale=100}
would then be formatted as "42%".
Or is the ICU4C meaning of this option the exact opposite?
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.
Another thought: an enumeration might be appropriate here. Something like:
scalingMode: "scale"
scales the number: 0.5 => 50%scalingMode: "passThrough"
passes through the number: 50 => 50%
(sorry for the quad-post)
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.
In that case, scale
is a rather sub-optimal choice, as it demonstrably can be understood as either "scale the number by this much" or "the scale extends to this value as the maximum".
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.
More suggestions, with some help from an LLM
enum PercentageScale { Fraction, Percentage }
enum InputMode { Decimal, Scaled }
enum ValueType { Normalized, Preformatted }
enum PercentMode { Ratio, Percent }
enum ScaleType { UnitInterval, WholePercent }
enum InputScale { PartsPerHundred, FinalPercent }
enum Scale { Raw, Scaled }
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.
Maybe style=raw
, as an alternative to a default style=scaled
?
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 would like to avoid any option with the unqualified style
name.
The _resolved value_ of an _expression_ with a `:percent` _function_ | ||
contains an implementation-defined numerical value | ||
of the _operand_ of the annotated _expression_ multiplied by 100, | ||
together with the resolved options' 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.
For clarity, and since "resolved value" and "options" are the terms, perhaps:
together with the resolved options' values. | |
together with the _resolved values_ of the _options_. |
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.
Variants of this same snippet are used in nearly all the functions. This change would be better made separately, affecting all of them at once.
But yes, referring to the options' resolved values would be appropriate, but note that this isn't the same as options, given that the resolved options are determined by the function handler. In practice they can include ones coming from the operand as well, and don't necessarily contain all of the options.
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.
Perhaps "resolved values of the resolved list of options"? Oh the pedantry...
Option values with the following names are however discarded if included in the _operand_: | ||
|
||
- `compactDisplay` | ||
- `notation` | ||
- `select` |
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.
Just say that all options not named in the :percent
function's list above are discarded?
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.
That would be different from what we do with other functions, such as :integer
, and it would make extensibility difficult.
An implementation could support additional options that are set in the calling code on the value being formatted, and are understood by the formatter. For a somewhat silly example, an implementation could support colour as a property of numbers, and format a "green 0.42" so that the % sign was also green in the output. If we here said that all options not explicitly listed are discarded, this kind of extensibility would not be possible.
For the purposes of formatting, | ||
the numeric value of the _operand_ is multiplied by 100. |
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.
ICU4C calls it "scale" or "multiplier"
ICU4X calls it "multiply_pow10"
I don't think we've had a proper bikeshedding session on this before. I've sort-of named it what I felt like naming it and no one ever pushed back with better names.
During today's discussion, we noted that percent formatting is already available via This means that introducing To still support the multiplicative behaviour (which
|
I'm dubious that this is a good idea. The Note that this would mean that Also, there are other formats that we're ignoring (because they are much less common) which are supported by CLDR data, which is per-mille and per-myriad formatting. We should just solve the problem. The existence of these suggests a convenience function or maybe a convenience unit. Consider:
|
I still have the weakly held position that :percent carries its own weight, and we should just add it and move on. It doesn't completely duplicate functionality: you use :percent if you want scaling, and :unit unit=percent if not. |
Fixes #956
A separate
:percent
function is added, and thestyle
option dropped from:number
and:integer
.As proposed in #987, selection is not enabled for
:percent
.I've also left out the
notation
andcompactDisplay
options, as I'm not aware of any actual use cases combining them with percent formatting.