Skip to content

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

Closed
@caridy

Description

@caridy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: numbersComponent: numbers, currency, unitss: in progressStatus: the issue has an active proposal

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions