Intl.Locale.prototype.numeric
Intl.Locale
实例的 numeric
访问器属性返回此语言环境是否具有针对数字字符的特殊排序规则处理。
¥The numeric
accessor property of Intl.Locale
instances returns whether this locale has special collation handling for numeric characters.
描述
¥Description
与 caseFirst
一样,numeric
表示对语言环境所使用的排序规则的修改。numeric
是一个布尔值,这意味着它可以是 true
或 false
。如果 numeric
设置为 false
,则不会对字符串中的数值进行特殊处理。如果 numeric
设置为 true
,则区域设置在整理字符串时将考虑数字字符。这种特殊的数字处理意味着十进制数字序列将作为数字进行比较。例如,字符串 "A-21" 将被视为小于 "A-123"。
¥Like caseFirst
, numeric
represents a modification to the collation rules utilized by the locale. numeric
is a boolean value, which means that it can be either true
or false
. If numeric
is set to false
, there will be no special handling of numeric values in strings. If numeric
is set to true
, then the locale will take numeric characters into account when collating strings. This special numeric handling means that sequences of decimal digits will be compared as numbers. For example, the string "A-21" will be considered less than "A-123".
示例
通过区域设置字符串设置数值
¥Setting the numeric value via the locale string
在 Unicode 语言环境字符串规范 中,numeric
代表的值对应于键 kn
。kn
被视为区域设置字符串 "扩展子标签"。这些子标签添加有关区域设置的附加数据,并使用 -u
扩展键添加到区域设置标识符。因此,可以将 numeric
值添加到传递到 Intl.Locale()
构造函数的初始区域设置标识符字符串中。要设置 numeric
值,请首先将 -u
扩展键添加到字符串中。接下来,添加 -kn
扩展键以指示你要添加 numeric
的值。最后,将 numeric
值添加到字符串中。如果要将 numeric
设置为 true
,则添加 kn
键就足够了。要将值设置为 false
,你必须在 kn
键后添加 "false"
来指定。
¥In the Unicode locale string spec, the values that numeric
represents correspond to the key kn
. kn
is considered a locale string "extension subtag". These subtags add additional data about the locale, and are added to locale identifiers by using the -u
extension key. Thus, the numeric
value can be added to the initial locale identifier string that is passed into the Intl.Locale()
constructor. To set the numeric
value, first add the -u
extension key to the string. Next, add the -kn
extension key to indicate that you are adding a value for numeric
. Finally, add the numeric
value to the string. If you want to set numeric
to true
, adding the kn
key will suffice. To set the value to false
, you must specify in by adding "false"
after the kn
key.
const locale = new Intl.Locale("fr-Latn-FR-u-kn-false");
console.log(locale.numeric); // Prints "false"
通过配置对象参数设置数值
¥Setting the numeric value via the configuration object argument
Intl.Locale()
构造函数有一个可选的配置对象参数,可用于传递扩展类型。将配置对象的 numeric
属性设置为所需的 numeric
值并将其传递到构造函数中。
¥The Intl.Locale()
constructor has an optional configuration object argument, which can be used to pass extension types. Set the numeric
property of the configuration object to your desired numeric
value and pass it into the constructor.
const locale = new Intl.Locale("en-Latn-US", { numeric: true });
console.log(locale.numeric); // Prints "true"
规范
Specification |
---|
ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.numeric |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also