Coder Social home page Coder Social logo

Comments (6)

sffc avatar sffc commented on June 17, 2024

Related:

from proposal-intl-numberformat-v3.

sffc avatar sffc commented on June 17, 2024

CC @romulocintra

Intl.NumberFormat has options that are decimal-specific. For example, how would you format the following?

  • { style: "ordinal", notation: "compact" }
  • { style: "ordinal", useGrouping: true }

from proposal-intl-numberformat-v3.

Bx1 avatar Bx1 commented on June 17, 2024
* `{ style: "ordinal", notation: "compact" }`

For English (compact long, depends on rounding):

  • 3 → 3rd
  • 1003 → 1000th
  • 2018 → 2000th
  • 1234567 → 120000th

For English (compact short, depends on rounding):

  • 3 → 3rd
  • 1003 → 1Kth (thousandth)
  • 2018 → 2Kth (thousandth)
  • 1234567 → 1Mth (millionth)
* `{ style: "ordinal", useGrouping: true }`

For English:

  • 3 → 3rd
  • 1003 → 1,003rd
  • 2018 → 2,018th

BUT,

sincerely, I think current spec for NumberFormat is... bad (unclear, tricky, complex, not optimized, etc.). I think everything which is connected to any numbers is tossed and mixed in one bag -- called Intl.NumberFormat.

My opinion is that Intl.NumberFormat should be divided.

My proposal is as follows:

  1. We have classes:
  • Intl.NumberFormat
  • Intl.CurrencyFormat
  • Intl.MeasurementFormat
  • Intl.NumeralFormat (name from Numeral part of speech, to force that this is a language formatter)
  1. We have one, single class to format number (Intl.NumberFormat). With style, grouping, maximumSignificantDigits, rounding and other options strictly connected to mathematical, abstract idea of numbers.

  2. Following classes (Intl.CurrencyFormat, Intl.MeasurementFormat, Intl.NumeralFormat) have their own formatting options. For example Intl.CurrencyFormat should have current currency, currencySign, currencyDisplay, etc. On the other hand Intl.MeasurementFormat should have current unit, unitDisplay, signDisplay, etc. Current style called style: percent should be used as unit, so it must be formatted by Intl.MeasurementFormat.

  3. Classes Intl.CurrencyFormat, Intl.MeasurementFormat, Intl.NumeralFormat have attribute called numberFormatter which should be an instance of Intl.NumberFormat class. This numberFormatter will be delegated to "construct" value of the number, and container class will be designed to "construct" result (eg. currency number) from this formatted number and their own settings. It can be initially required that NumberFormat has the same Locale as "container class" like CurrencyFormat.

const measurementFormatter = new Intl.MeasurementFormat('en-US', { unit: 'meter' });
const numberFormatter = new Intl.NumberFormat('en-US', { signDisplay: 'never', notation: 'engineering' });
measurementFormatter.numberFormatter = numberFormatter;
measurementFormatter.format(11);

  1. The last class (Intl.NumeralFormat) should be used to format numbers into numerals (ordinal, spell-out, etc.). It should also
    have own settings. For example: ordinal numbers can be formatted shortly as "3." or "3rd", but it also can be spelled-out as "third".

This composition would reduce weird complexity from current NumberFormat and would enable developing new features.

from proposal-intl-numberformat-v3.

sffc avatar sffc commented on June 17, 2024

Thanks for the feedback.

The all-in-one design for NumberFormat is intentional, because most of the same settings are used in all of the style options. The combination of style and notation allows for powerful combinations with a minimal learning curve.

For example, the difference between Intl.NumberFormat("en", { style: "unit", unit: "meter" }) and Intl.UnitFormat("en", { unit: "meter" }) is largely one of taste.

It's possible that we could have gone the direction of separate formatters, but the very first version of ECMA-402 already had "currency" and "percent" as style options, so when we added "unit" more recently, it only made sense to continue the trend.

I agree that the spec is complex. I would like it to be less complex, but that will require some changes to how we deal with locale data (tc39/ecma402#210).

{ style: "ordinal", notation: "compact" }

Actually I think "1 thousandth" makes sense here for long. For short, "1 Kth" might be acceptable.

from proposal-intl-numberformat-v3.

Bx1 avatar Bx1 commented on June 17, 2024

Thanks for your feedback too. Thanks for your commitment in this project.

I hope these ideas would help to improve future web development (for web clients developers and browser developers).

from proposal-intl-numberformat-v3.

sffc avatar sffc commented on June 17, 2024

I'm going to close this issue as out of scope for this proposal, because this proposal is already at Stage 2 and adding the RBNF dependency is too big of a change. However, I have seen broad support for this feature, so I hope it can be actioned in an upcoming release of ECMA-402. Follow this thread for updates:

tc39/ecma402#494

from proposal-intl-numberformat-v3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.