Comments (6)
Related:
from proposal-intl-numberformat-v3.
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.
* `{ 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:
- 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)
-
We have one, single class to format number (
Intl.NumberFormat
). Withstyle
,grouping
,maximumSignificantDigits
, rounding and other options strictly connected to mathematical, abstract idea of numbers. -
Following classes (
Intl.CurrencyFormat
,Intl.MeasurementFormat
,Intl.NumeralFormat
) have their own formatting options. For exampleIntl.CurrencyFormat
should have currentcurrency
,currencySign
,currencyDisplay
, etc. On the other handIntl.MeasurementFormat
should have currentunit
,unitDisplay
,signDisplay
, etc. Current style calledstyle: percent
should be used as unit, so it must be formatted byIntl.MeasurementFormat
. -
Classes
Intl.CurrencyFormat
,Intl.MeasurementFormat
,Intl.NumeralFormat
have attribute callednumberFormatter
which should be an instance ofIntl.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);
- 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.
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.
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.
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:
from proposal-intl-numberformat-v3.
Related Issues (20)
- Intl.PluralRules does not have the [[RoundingMode]] internal slot required by FormatNumericToString HOT 2
- `formatRangeToParts` produces an empty `source` when `FormatApproximately` is used HOT 2
- FormatNumericToString - isNegative first value clarification HOT 2
- Ordinal formating in NumberFormat HOT 2
- useGrouping's Note is inconsistent with the actual code HOT 1
- ResolvePluralRange does not account for approximately formatted ranges HOT 2
- Clarify that literals can be changed in CollapseNumberRange
- Should "approximatelySign" be renamed to "approximateSign"? HOT 1
- Can the order in which properties are read be more comprehensible? HOT 8
- Can ToRawPrecision and ToRawFixed be made more deterministic? HOT 1
- String(Intl)MV should be defined in ECMA-262 HOT 2
- `FormatNumericToString` will errantly convert -0 to +0 then back to -0 before calling `ToRaw[Precision|Fixed]` HOT 1
- Missing 𝔽 subscript for -0 in FormatNumericToString
- Meta: cross-references are gone
- Simplify PartitionNumberRangePattern
- Hard time to implement IntlMathematicalValue HOT 12
- Clarification on what "precision" means in roundingPriority: morePrecision/lessPrecision HOT 4
- Only passing `roundingIncrement` will throw an error. HOT 3
- Limit exponent of intl mathematical value HOT 7
- Lack of [[Source]] in FormatNumericRangeToParts if returned by FormatApproximately HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-intl-numberformat-v3.