?
u
/
The NumberFormat constructor is the %NumberFormat% intrinsic object and a standard built-in property of the Intl object. Behaviour common to all service constructor properties of the Intl object is specified in
When the Intl.NumberFormat
function is called with optional arguments locales and options, the following steps are taken:
The abstract operation InitializeNumberFormat accepts the arguments numberFormat (which must be an object), locales, and options. It initializes numberFormat as a NumberFormat object. The following steps are taken:
The following algorithm refers to the type
nonterminal from UTS 35's Unicode Locale Identifier grammar.
type
nonterminal, throw a The abstract operation SetNumberFormatDigitOptions applies digit options used for number formatting onto the intl object. It is used by both Intl.NumberFormat and Intl.PluralRules.
The abstract operation SetNumberFormatUnitOptions resolves the user-specified options relating to units onto the intl object.
The Intl.NumberFormat constructor has the following properties:
The value of Intl.NumberFormat.prototype
is
This property has the attributes { [[Writable]]:
When the supportedLocalesOf
method is called with arguments locales and options, the following steps are taken:
The value of the [[AvailableLocales]] internal slot is implementation-defined within the constraints described in
The value of the [[RelevantExtensionKeys]] internal slot is «
The value of the [[LocaleData]] internal slot is implementation-defined within the constraints described in
The Intl.NumberFormat prototype object is itself an ordinary object. %NumberFormat.prototype% is not an Intl.NumberFormat instance and does not have an [[InitializedNumberFormat]] internal slot or any of the other internal slots of Intl.NumberFormat instance objects.
The initial value of Intl.NumberFormat.prototype.constructor
is
The initial value of the @@toStringTag property is the String value
This property has the attributes { [[Writable]]:
Intl.NumberFormat.prototype.format is an accessor property whose set accessor function is
Array.prototype.map
or other functions.
This is considered a historical artefact, as part of a convention which is no longer followed for new features, but is preserved to maintain compatibility with existing programs.
When the formatToParts
method is called with an optional argument value, the following steps are taken:
When the formatRange
method is called with arguments start and end, the following steps are taken:
When the formatRangeToParts
method is called with arguments start and end, the following steps are taken:
This function provides access to the locale and options computed during initialization of the object.
Internal Slot | Property |
---|---|
[[Locale]] | |
[[NumberingSystem]] | |
[[Style]] | |
[[Currency]] | |
[[CurrencyDisplay]] | |
[[CurrencySign]] | |
[[Unit]] | |
[[UnitDisplay]] | |
[[MinimumIntegerDigits]] | |
[[MinimumFractionDigits]] | |
[[MaximumFractionDigits]] | |
[[MinimumSignificantDigits]] | |
[[MaximumSignificantDigits]] | |
[[UseGrouping]] | |
[[Notation]] | |
[[CompactDisplay]] | |
[[SignDisplay]] | |
[[RoundingMode]] | |
[[RoundingIncrement]] | |
[[TrailingZeroDisplay]] |
Intl.NumberFormat instances are ordinary objects that inherit properties from
Intl.NumberFormat instances have an [[InitializedNumberFormat]] internal slot.
Intl.NumberFormat instances also have several internal slots that are computed by the constructor:
Identifier | Description | Examples: Round to 0 fraction digits | ||||
---|---|---|---|---|---|---|
-1.5 | 0.4 | 0.5 | 0.6 | 1.5 | ||
Toward positive infinity | ➕ [-1] | ➕ [1] | ➕ [1] | ➕ [1] | ➕ [2] | |
Toward negative infinity | ➖ [-2] | ➖ [0] | ➖ [0] | ➖ [0] | ➖ [1] | |
Away from zero | ➖ [-2] | ➕ [1] | ➕ [1] | ➕ [1] | ➕ [2] | |
Toward zero | ➕ [-1] | ➖ [0] | ➖ [0] | ➖ [0] | ➖ [1] | |
Ties toward positive infinity | ➕ [-1] | ➖ [0] | ➕ [1] | ➕ [1] | ➕ [2] | |
Ties toward negative infinity | ➖ [-2] | ➖ [0] | ➖ [0] | ➕ [1] | ➖ [1] | |
Ties away from zero | ➖ [-2] | ➖ [0] | ➕ [1] | ➕ [1] | ➕ [2] | |
Ties toward zero | ➕ [-1] | ➖ [0] | ➖ [0] | ➕ [1] | ➖ [1] | |
Ties toward even cardinality | ➖ [-2] | ➖ [0] | ➖ [0] | ➕ [1] | ➕ [2] |
Finally, Intl.NumberFormat instances have a [[BoundFormat]] internal slot that caches the function returned by the format accessor (
When the CurrencyDigits abstract operation is called with an argument currency (which must be an uppercase String value), the following steps are taken:
A Number format function is an anonymous built-in function that has a [[NumberFormat]] internal slot.
When a Number format function F is called with optional argument value, the following steps are taken:
The
The FormatNumericToString abstract operation is called with arguments intlObject (which must be an object with [[RoundingType]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], and [[MaximumFractionDigits]] internal slots), and x (which must be a Number or BigInt value), and returns a Record containing two values: x as a String value with digits formatted according to the five formatting parameters in the field [[FormattedString]], and the final floating decimal value of x after rounding has been performed in the field [[RoundedNumber]].
The FormatNumericToString abstract operation is called with arguments intlObject (which must be an object with [[RoundingMode]], [[RoundingType]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[RoundingIncrement]], and [[TrailingZeroDisplay]] internal slots), and x (which must be a mathematical value or
The PartitionNotationSubPattern abstract operation is called with arguments numberFormat (which must be an object initialized as a NumberFormat), x (which is a numeric value an
Numbering System | Digits |
---|---|
adlm | U+1E950 to U+1E959 |
ahom | U+11730 to U+11739 |
arab | U+0660 to U+0669 |
arabext | U+06F0 to U+06F9 |
bali | U+1B50 to U+1B59 |
beng | U+09E6 to U+09EF |
bhks | U+11C50 to U+11C59 |
brah | U+11066 to U+1106F |
cakm | U+11136 to U+1113F |
cham | U+AA50 to U+AA59 |
deva | U+0966 to U+096F |
diak | U+11950 to U+11959 |
fullwide | U+FF10 to U+FF19 |
gong | U+11DA0 to U+11DA9 |
gonm | U+11D50 to U+11D59 |
gujr | U+0AE6 to U+0AEF |
guru | U+0A66 to U+0A6F |
hanidec | U+3007, U+4E00, U+4E8C, U+4E09, U+56DB, U+4E94, U+516D, U+4E03, U+516B, U+4E5D |
hmng | U+16B50 to U+16B59 |
hmnp | U+1E140 to U+1E149 |
java | U+A9D0 to U+A9D9 |
kali | U+A900 to U+A909 |
khmr | U+17E0 to U+17E9 |
knda | U+0CE6 to U+0CEF |
lana | U+1A80 to U+1A89 |
lanatham | U+1A90 to U+1A99 |
laoo | U+0ED0 to U+0ED9 |
latn | U+0030 to U+0039 |
lepc | U+1C40 to U+1C49 |
limb | U+1946 to U+194F |
mathbold | U+1D7CE to U+1D7D7 |
mathdbl | U+1D7D8 to U+1D7E1 |
mathmono | U+1D7F6 to U+1D7FF |
mathsanb | U+1D7EC to U+1D7F5 |
mathsans | U+1D7E2 to U+1D7EB |
mlym | U+0D66 to U+0D6F |
modi | U+11650 to U+11659 |
mong | U+1810 to U+1819 |
mroo | U+16A60 to U+16A69 |
mtei | U+ABF0 to U+ABF9 |
mymr | U+1040 to U+1049 |
mymrshan | U+1090 to U+1099 |
mymrtlng | U+A9F0 to U+A9F9 |
newa | U+11450 to U+11459 |
nkoo | U+07C0 to U+07C9 |
olck | U+1C50 to U+1C59 |
orya | U+0B66 to U+0B6F |
osma | U+104A0 to U+104A9 |
rohg | U+10D30 to U+10D39 |
saur | U+A8D0 to U+A8D9 |
segment | U+1FBF0 to U+1FBF9 |
shrd | U+111D0 to U+111D9 |
sind | U+112F0 to U+112F9 |
sinh | U+0DE6 to U+0DEF |
sora | U+110F0 to U+110F9 |
sund | U+1BB0 to U+1BB9 |
takr | U+116C0 to U+116C9 |
talu | U+19D0 to U+19D9 |
tamldec | U+0BE6 to U+0BEF |
telu | U+0C66 to U+0C6F |
thai | U+0E50 to U+0E59 |
tibt | U+0F20 to U+0F29 |
tirh | U+114D0 to U+114D9 |
tnsa | U+16AC0 to U+16AC9 |
vaii | U+A620 to U+A629 |
wara | U+118E0 to U+118E9 |
wcho | U+1E2F0 to U+1E2F9 |
The FormatNumeric abstract operation is called with arguments numberFormat (which must be an object initialized as a NumberFormat) and x (which must be a Number or BigIntIntl mathematical value), and performs the following steps:
The FormatNumericToParts abstract operation is called with arguments numberFormat (which must be an object initialized as a NumberFormat) and x (which must be a Number or BigIntIntl mathematical value), and performs the following steps:
ToRawPrecision is an abstract operation that involves solving the following equation, which returns a valid mathematical value given integer inputs:
When the ToRawPrecision abstract operation is called with arguments x (which must be a finite non-negative Number or BigIntmathematical value), minPrecision, and maxPrecision (both must be integers between 1 and 21), and unsignedRoundingMode (a specification type from the
ToRawFixed is an abstract operation that involves solving the following equation, which returns a valid mathematical value given integer inputs:
When the ToRawFixed abstract operation is called with arguments x (which must be a finite non-negative Number or BigIntmathematical value), minFraction, and maxFraction (which must be integers between 0 and 20), roundingIncrement (an integer), and unsignedRoundingMode (a specification type from the
The UnwrapNumberFormat abstract operation returns the NumberFormat instance
of its input object, which is either the value itself or a value associated
with it by
The abstract operation GetNumberFormatPattern considers the resolved unit-related options in the number format object along with the final scaled and rounded number being formatted (an
The abstract operation GetNotationSubPattern considers the resolved notation and exponent, and returns a String value for the notation sub pattern as described in
The abstract operation ComputeExponent computes an exponent (power of ten) by which to scale x according to the number formatting settings. It handles cases such as 999 rounding up to 1000, requiring a different exponent.
The abstract operation ComputeExponentHelperComputeExponentForMagnitude computes an exponent by which to scale a number of the given magnitude (power of ten of the most significant digit) according to the locale and the desired notation (scientific, engineering, or compact).
The syntax-directed operation StringIntlMV takes no arguments.
The conversion of a
It is defined piecewise over the following productions:
The abstract operation ToIntlMathematicalValue takes argument value. It returns value converted to an Intl mathematical value, which is a mathematical value together with
The abstract operation GetUnsignedRoundingMode returns the rounding mode that should be applied to the absolute value of a number to produce the same result as if roundingMode, one of the String values in the
Identifier | Sign | Unsigned Rounding Mode |
---|---|---|
positive | ||
negative | ||
positive | ||
negative | ||
positive | ||
negative | ||
positive | ||
negative | ||
positive | ||
negative | ||
positive | ||
negative | ||
positive | ||
negative | ||
positive | ||
negative | ||
positive | ||
negative |
The abstract operation ApplyUnsignedRoundingMode considers x (a mathematical value), bracketed below by r1 (a mathematical value) and above by r2 (a mathematical value), and returns either r1 or r2 according to unsignedRoundingMode (a specification type from the
The abstract operation PartitionNumberRangePattern creates the parts for a localized number range according to x (which must be an
The FormatApproximately abstract operation modifies result, which must be a List of Record values as described in
The CollapseNumberRange abstract operation modifies result, which must be a List of Record values as described in
For example, an implementation may choose to remove the currency symbol following the range separator, to produce "$3–5" instead of "$3–$5".
The implementation may choose to modify symbols for grammatical correctness; for example, "0.5 miles–1 mile" may become "0.5–1 miles".
Returning result unmodified is guaranteed to be a correct implementation of CollapseNumberRange.
The FormatNumericRange abstract operation is called with arguments numberFormat (which must be an object initialized as a NumberFormat), x (which must be an
The FormatNumericRangeToParts abstract operation is called with arguments numberFormat (which must be an object initialized as a NumberFormat), x (which must be an