blob: 38ab78a04590c3c136ae376a09d57f5892d04ea3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
---
title: Intl.Locale.prototype.numeric
slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric
tags:
- Internationalization
- Intl
- JavaScript
- Property
- Prototype
- Reference
- プロパティ
- 国際化
translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale/numeric
---
<div>{{JSRef}}</div>
<p><span class="seoSummary"><strong><code>Intl.Locale.prototype.numeric</code></strong> プロパティは、ロケールが特別な数字の照合処理を行うかどうかを返すアクセサプロパティです。</span></p>
<h2 id="Description" name="Description">解説</h2>
<p>{{jsxref("Locale.caseFirst", "Intl.Locale.caseFirst")}} と同様、 <code>numeric</code> はロケールが使用する照合規則を変更するものです。 <code>numeric</code> は {{jsxref("boolean", "Boolean")}} 値で、 <code>true</code> か <code>false</code> のどちらかになります。 <code>numeric</code> を <code>false</code> に設定した場合は、文字列内の数値を特別に扱うことはありません。 <code>numeric</code> を <code>true</code> に設定した場合は、ロケールは文字列を照合する際に数値を考慮します。この数値の特別な扱いとは、数字の並びを数値として比較するということです。例えば、 "A-21" という文字列は "A-123" よりも小さいとみなされます。</p>
<h2 id="Examples" name="Examples">例</h2>
<h3 id="Setting_the_numeric_value_via_the_locale_string" name="Setting_the_numeric_value_via_the_locale_string">ロケール文字列から <code>numeric</code> の値を設定</h3>
<p><a href="https://www.unicode.org/reports/tr35/" rel="noopener">Unicode ロケール文字列仕様書</a>では、 <code>numeric</code> が表す値はキー <code>kn</code> に対応しています。 <code>kn</code> はロケール文字列の「拡張サブタグ」とみなされます。これらのサブタグは、ロケールに関する追加データを追加するもので、拡張キー <code>-u</code> を使用してロケール識別子に追加されます。このようして、 <code>numeric</code> の値を {{jsxref("Locale/Locale", "Locale")}} コンストラクターに渡される初期のロケール識別子文字列に追加することができます。 <code>numeric</code> の値を設定するには、まず文字列に <code>-u</code> 拡張キーを追加します。次に、 <code>-kn</code> 拡張キーを追加して、 <code>numeric</code> の値を追加していることを示します。最後に、文字列に <code>numeric</code> の値を追加します。 <code>numeric</code> を <code>true</code> に設定したい場合は、単に <code>kn</code> キーを追加するだけで十分です。値を <code>false</code> にするには、 <code>kn</code> キーの後に "<code>false</code>" を指定する必要があります。</p>
<pre class="brush: js">let numericViaStr = new Intl.Locale("fr-Latn-FR-u-kn-false");
console.log(numericStr.numeric); // "false" と表示</pre>
<h3 id="Setting_the_numeric_value_via_the_configuration_object_argument" name="Setting_the_numeric_value_via_the_configuration_object_argument">構成オブジェクト引数から <code>numeric</code> の値を設定</h3>
<p>{{jsxref("Locale/Locale", "Intl.Locale")}} コンストラクターには、オプションで構成オブジェクトの引数があり、これを使用して拡張の種類を渡すことができます。構成オブジェクトの <code>numeric</code> プロパティを任意の <code>numeric</code> に設定し、コンストラクターに渡します。</p>
<pre class="brush: js">let numericViaObj= new Intl.Locale("en-Latn-US", {numeric: true});
console.log(us12hour.numeric); // "true" と表示
</pre>
<h2 id="Specifications" name="Specifications">仕様書</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">仕様書</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('ES Int Draft', '#sec-Intl.Locale.prototype.numeric')}}</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2>
<div>{{Compat("javascript.builtins.Intl.Locale.numeric")}}</div>
<h2 id="See_also" name="See_also">関連情報</h2>
<ul>
<li>{{jsxref("Locale", "Intl.Locale")}}</li>
</ul>
|