Skip to content

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

aphillips
Copy link
Member

This document is focused for now on documenting the options.

This document is focused for now on documenting the options.
@aphillips aphillips added design Design document or issues related to design functions Issue pertains to the default function set LDML48 LDML48 Release labels Apr 7, 2025

#### Use a dedicated `:percent` function

Use a new function `:percent` dedicated to percentages.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider names besides :percent?

The function could apply to all dimensionless units including permille, permillion, perbillion, etc.

For example: {$var :dimensionless unit=permillion}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider other names. I'll add that option.

I'm not wild about unit=percent (mille, billion, etc. etc.). It's verbose and the other uses seems rare. Really only percent and permille are backed by CLDR data. The others strike me as special uses for unit or number formatting.

Comment on lines 160 to 161
#### Scaling
Implementation always scales the number. The value `0.5` formats as `50%`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go with the "always scales" approach, :unit can still be used to not scale.

@aphillips aphillips requested review from gibson042 and macchiati April 8, 2025 00:15
Copy link
Collaborator

@eemeli eemeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A first pass. I don't agree with the currently proposed design, but let's first get the available options better presented.

It would be nice to have more example code for the options.

Comment on lines +199 to +200
Implementation automatically does (or does not) scale.
There is an option to switch to the other behavior.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Implementation automatically does (or does not) scale.
There is an option to switch to the other behavior.
Formatter automatically does (or does not) scale.
There is an option to switch to the other behavior.
The option here may be:
- An option `scaling` with boolean values `true` and `false`.
- An option `scale` with a small set of supported integer values, possibly only `1` and `100`.

Comment on lines +92 to +94
- Allow `unit=percent` in `:unit` that is identical to `:percent` in formatting performance,
for compatibility with CLDR units,
but document that this usage is not preferred.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this mean that :unit unit=percent would or would not apply scaling? And why do we need or benefit from compatibility with CLDR units here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need or benefit from compatibility with CLDR units here?

We don't have to be compatible, except that currently the definition of the unit option values is completely delegated to the unit identifiers found here in TR35. It would be unfortunate to say "unit identifiers except this one specific one"

Would this mean that :unit unit=percent would or would not apply scaling?

That's a good question. In the most recent WG discussion, there was a sentiment that we should make them behave identically to avoid confusion. There's an equal sentiment that they should be opposite each other (for utility). Here I'm trying to express equivalent performance without binding to a specific scaling/not-scaling choice (since that is separate).

Comment on lines +191 to +192
- Only percent and permille are backed with CLDR data and symbols.
Other scales would impose an implementation burden.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLDR has data for other scales, too, via portion units.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not really percent/per mille type scaling though, is it?

{{Completion: {$n :unit unit=percent}.}}
```

#### Use `:math multiply` to scale
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note my concern about implementation burden due to having to support a more general function than we actually need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design document or issues related to design functions Issue pertains to the default function set LDML48 LDML48 Release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants