Intl.Locale.prototype.numeric - JavaScript 编辑

The Intl.Locale.prototype.numeric property is an accessor property that returns whether the locale has special collation handling for numeric characters.

Description

Like Intl.Locale.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".

Examples

Setting the numeric value via the locale string

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 inital locale identifier string that is passed into the 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.

let numericViaStr = new Intl.Locale("fr-Latn-FR-u-kn-false");
console.log(numericStr.numeric); // Prints "false"

Setting the numeric value via the configuration object argument

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.

let numericViaObj= new Intl.Locale("en-Latn-US", {numeric: true});
console.log(us12hour.numeric); // Prints "true"

Specifications

Specification
ECMAScript Internationalization API (ECMA-402)

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:50 次

字数:4882

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文