explore associating a unit with a number ?
- Stage: Unstaged
- Status: Active
- ECMAScript edition: —
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
This proposal introduces a protocol for associating units with numbers in Intl.NumberFormat formatting. It allows passing a unit as part of the format argument object, solving the data model gap for MessageFormat 2.0.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
TC39 Intl Unit Protocol
Status: Stage 2
Champion: Shane F Carr (Google i18n)
History:
- Ask for Stage 1 @ 111th Meeting of TC39 (Notes)
- Ask for Stage 2 @ 113th Meeting of TC39 (Notes pending)
Draft Spec: https://tc39.es/proposal-intl-unit-protocol/
Background
The i18n community has converged on the principle that a number ought to be annotated with the quantity it is measuring. Unlike the localized decimal separators, numbering systems for digits, and grouping strategy, the unit is a core part of the data model to be formatted, not a style that gets applied by the formatter.
For example, when formatting messages, this allows the measurement to be localized with locale unit preferences.
A number annotated with a unit is the only data type required for MessageFormat 2.0 that does not have an analog in JavaScript. See: List of functions in MessageFormat 2.0.
Adding a new primordial, such as Amount, would solve this problem and multiple others impacting i18n. A key question is how Amount interfaces with Intl and how third-party libraries can implement an Amount-like object. The champions believe that this is a sufficiently different problem space that they are pursuing Intl Unit Protocol as a standalone proposal.
Proposed Solution
Add a protocol to Intl.NumberFormat.prototype.format that accepts a numeric type paired with a unit. The protocol should also be accepted by Intl.PluralRules.prototype.select.
Given these inputs:
The user can currently write:
With a protocol, the user can instead write:
Construction vs Formatting
Intl has long allowed constructors and formatting functions to be separate. This achieves two ends:
- The formatter can encapsulate the locale and options to specify the style and context of the value being formatted, such as when initializing a templating engine.
- Locale data can be initialized ahead of time, allowing increased efficiency when formatting multiple items in a loop.
By moving unit from the constructor bucket to the formatting bucket, we advance goal 1.
The proposal comes at some cost to goal 2, since loading the unit display name has some implementation cost that must now be deferred. We will work with ICU[4X] to minimize this cost.
Currencies
The protocol would allow currency units to be specified in a similar way.
Protocol does not require a unit
The protocol accepts objects with a value getter even if their unit getter returns undefined:
Conflicting Units
If the constructor has a unit and the unit is not the same as the one in the protocol, an exception will be thrown, since this is a programmer error.
When the Amount proposal advances, this can be changed to automatically convert the input unit to the formatter unit.
Unit not allowed if style is not "unit" or "currency"
If a unit is set in the protocol, but the formatter was not configured with style "unit" or "currency", an error will occur.
This helps implementations know that they need to load unit or currency data in the constructor, partially mitigating the "construction vs formatting" impact discussed above.
Range Formatting
Currently, formatting a range requires the units to be equal. This restriction may be relaxed in the future.
Integration with Future Proposals
The Amount proposal seeks to add a primordial encapsulating a numeric type with a unit. It will implement the Intl protocol specified here.
The Decimal proposal seeks to add a primordial that represents a decimal number in a form designed for correct and efficient arithmetic. It will likely be supported as another number type for the value field in the protocol.
Other fields could be added to this protocol in the future, such as alternative ways of expressing precision or an override to the number of significant digits specified in the constructor.