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

[Proposal] Compact Decimal Format to abbreviate large numbers #37

Closed
caridy opened this issue Sep 19, 2015 · 12 comments
Closed

[Proposal] Compact Decimal Format to abbreviate large numbers #37

caridy opened this issue Sep 19, 2015 · 12 comments
Labels
c: numbers Component: numbers, currency, units s: in progress Status: the issue has an active proposal
Milestone

Comments

@caridy
Copy link
Contributor

caridy commented Sep 19, 2015

CLDR contains the details to abbreviate large numbers, e.g.:

        "decimalFormats-numberSystem-latn": {
          "standard": "#,##0.###",
          "long": {
            "decimalFormat": {
              "1000-count-one": "0 thousand",
              "1000-count-other": "0 thousand",
              "10000-count-one": "00 thousand",
              "10000-count-other": "00 thousand",
              "100000-count-one": "000 thousand",
              "100000-count-other": "000 thousand",
              "1000000-count-one": "0 million",
              "1000000-count-other": "0 million",
              "10000000-count-one": "00 million",
              "10000000-count-other": "00 million",
              "100000000-count-one": "000 million",
              "100000000-count-other": "000 million",
              "1000000000-count-one": "0 billion",
              "1000000000-count-other": "0 billion",
              "10000000000-count-one": "00 billion",
              "10000000000-count-other": "00 billion",
              "100000000000-count-one": "000 billion",
              "100000000000-count-other": "000 billion",
              "1000000000000-count-one": "0 trillion",
              "1000000000000-count-other": "0 trillion",
              "10000000000000-count-one": "00 trillion",
              "10000000000000-count-other": "00 trillion",
              "100000000000000-count-one": "000 trillion",
              "100000000000000-count-other": "000 trillion"
            }
          },
          "short": {
            "decimalFormat": {
              "1000-count-one": "0K",
              "1000-count-other": "0K",
              "10000-count-one": "00K",
              "10000-count-other": "00K",
              "100000-count-one": "000K",
              "100000-count-other": "000K",
              "1000000-count-one": "0M",
              "1000000-count-other": "0M",
              "10000000-count-one": "00M",
              "10000000-count-other": "00M",
              "100000000-count-one": "000M",
              "100000000-count-other": "000M",
              "1000000000-count-one": "0B",
              "1000000000-count-other": "0B",
              "10000000000-count-one": "00B",
              "10000000000-count-other": "00B",
              "100000000000-count-one": "000B",
              "100000000000-count-other": "000B",
              "1000000000000-count-one": "0T",
              "1000000000000-count-other": "0T",
              "10000000000000-count-one": "00T",
              "10000000000000-count-other": "00T",
              "100000000000000-count-one": "000T",
              "100000000000000-count-other": "000T"
            }
          }
        },

@rxaviers proposed this feature a while ago IIRC, but I could find the thread, so I'm posting it here to formalize the proposal.

Proposal

This proposal goes hand-to-hand with the pluralization (#34) since it will have to compute what's the pluralization token to choose the right format (In the CLDR data you will see that for english we have a lot of *-count-one and *-count-other).

The initial proposal could be to add one more configuration to specify either:

a) best-fit for the abbreviation, which means we choose the biggest matching decimal from the segments
b) the decimal reference to force to use a particular formatting option (e.g.: 10000, which could produce 1234K);

new Intl.NumberFormat('en', { compact: 'best-fit' }).format(1234000); // 1.2M
new Intl.NumberFormat('en', { compact: '4-digits' }).format(1234000); // 1234K

Open questions

  • how to match this with currency values so we can produce something like $12M.
  • the name of the configuration option when creating a new Intl.NumberFormat()
  • 1M vs 1.2M
  • 1M vs 1 Million (this will probably require another configuration to specify long vs short.
  • rounding and custom rounding settings? (related to Proposal for stage 0 rxaviers/ecma402-number-format-round-option#1 (comment))

/cc @jfparadis @zbraniecki

@caridy
Copy link
Contributor Author

caridy commented Sep 19, 2015

More details about CLDR Compact Decimal Format here: http://www.unicode.org/cldr/charts/27/summary/pl.html#4032

@zbraniecki
Copy link
Member

Probably same algorithm will be useful as for issue #32. ("1.2 M" vs. "2.5 KB")

@srl295
Copy link
Member

srl295 commented Sep 22, 2015

Spec: UTS #35 (HEAD)

@rxaviers
Copy link
Member

cc @steveluscher due to its related proposal https://gist.github.com/steveluscher/4b54e08aa1e0536b7cb9

@steveluscher
Copy link

Can you link to this rounding discussion in your list of open questions, @caridy?

@caridy
Copy link
Contributor Author

caridy commented Sep 23, 2015

@steveluscher added.

@charoseth
Copy link

Any progress/plan for this proposal?
This is quite useful for some statistical data shown in analysis softwares for localization.

@caridy caridy added s: in progress Status: the issue has an active proposal s: help wanted Status: help wanted; needs proposal champion labels Dec 23, 2017
@caridy
Copy link
Contributor Author

caridy commented Dec 23, 2017

It is an active proposal, but we need a champion!

@sffc
Copy link
Contributor

sffc commented Feb 12, 2018

See my follow-up in #215

@snewcomer
Copy link

Here is a library being used in applications across the Ember community based on this proposal.

JS lib: https://github.com/snewcomer/cldr-compact-number
Ember addon: https://github.com/snewcomer/ember-short-number

@anba
Copy link
Contributor

anba commented Mar 16, 2020

The new notation option provides this setting when "compact" is used:

js> print(new Intl.NumberFormat('en', { notation: "compact", compactDisplay: "long" }).format(1_000_000))
1 million

@sffc
Copy link
Contributor

sffc commented Mar 16, 2020

Yep, the proposal has been merged. Closing as Fixed

@sffc sffc closed this as completed Mar 16, 2020
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: in progress Status: the issue has an active proposal
Projects
None yet
Development

No branches or pull requests

9 participants