Skip to content
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

Allow compact notation to depend on style #810

Open
sffc opened this issue Jul 25, 2023 · 3 comments
Open

Allow compact notation to depend on style #810

sffc opened this issue Jul 25, 2023 · 3 comments
Labels
c: numbers Component: numbers, currency, units s: discuss Status: TG2 must discuss to move forward

Comments

@sffc
Copy link
Contributor

sffc commented Jul 25, 2023

Currently GetNotationSubPattern is a self-contained operation: https://tc39.es/ecma402/#sec-getnotationsubpattern

However, the notation subpattern can depend on the style. In ICU, this is already the case for currency, and it is likely useful for percent and unit styles as well.

Compact without currency:
https://unicode.org/cldr/charts/43/by_type/numbers.compact_decimal_formatting.html#76d709105676a7e5

Compact with currency:
https://unicode.org/cldr/charts/43/by_type/numbers.compact_decimal_formatting.html#122a473b23a455b1

By allowing this dependency, it could also give implementations more flexibility to use SI prefixes when style is "unit", instead of the default compact suffixes for that locale. CC @ljharb @ctcpip

@sffc sffc added s: discuss Status: TG2 must discuss to move forward c: numbers Component: numbers, currency, units labels Jul 25, 2023
@sffc sffc added this to Other Issues in ECMA-402 Meeting Topics Jul 25, 2023
@ctcpip
Copy link
Member

ctcpip commented Jul 25, 2023

not as confusing:

const numFormat = new Intl.NumberFormat('en-US', { style: 'unit', unit: 'byte', notation: 'compact' });

let num = 1;

for (let i = 0; i < 15; i++) {
  console.log(numFormat.format(num));
  num *= 10;
}
1 byte
10 byte
100 byte
1K byte
10K byte
100K byte
1M byte
10M byte
100M byte
1B byte
10B byte
100B byte
1T byte
10T byte
100T byte

more confusing:

const numFormat = new Intl.NumberFormat('en-US', { style: 'unit', unit: 'byte', notation: 'compact', unitDisplay: 'narrow' });

let num = 1;

for (let i = 0; i < 15; i++) {
  console.log(numFormat.format(num));
  num *= 10;
}
1B
10B
100B
1KB
10KB
100KB
1MB
10MB
100MB
1BB
10BB
100BB
1TB
10TB
100TB

@ljharb
Copy link
Member

ljharb commented Jul 25, 2023

If the unit is "byte", why would anyone describe it in terms of millions/billions/trillions instead of mega/giga/tera?

@ctcpip
Copy link
Member

ctcpip commented Dec 14, 2023

see also: #730

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: numbers Component: numbers, currency, units s: discuss Status: TG2 must discuss to move forward
Projects
Development

No branches or pull requests

3 participants