JavaScript

Intl.PluralRules() コンストラクター


編集:2023.01.11 by T.A.

[Edge]。→

新しい Intl.PluralRules オブジェクトを生成して返します。

構文
new Intl.PluralRules([locales[, options]])
locales 省略可 言語タグを持つ文字列、またはそのような文字列の配列。→Intl:locales
options 省略可。以下のプロパティと値を 1 組以上持つオブジェクト。
localeMatcher
ロケールの照合アルゴリズムを表す文字列。値は以下の何れか。
lookup
best fit (既定値)

Intl:マッチング アルゴリズム

type
書式化の種別を表す文字列。値は以下の何れか。
cardinal 基数(物の数量を表す)。(既定値)
ordinal 序数(物事の順序や順位を表す)

例: 英語「1st」「2nd」「3rd」

minimumIntegerDigits
整数部の最小桁数を表す数値。値: 1~21。既定値: 1。
minimumFractionDigits
小数部の最小桁数を表す数値。値: 0~20。¶mdn: 通常の数とパーセントの形式の既定値は 0 です。通貨形式の既定値は、ISO 4217 通貨コード リストで提供される下位単位の桁数です(リストに情報がない場合は 2 です)。
maximumFractionDigits
小数部の最大桁数を表す数値。値: 0~20。¶mdn: 通常の数の形式では既定値は minimumFractionDigits と 3 の大きい方です。通貨形式の既定値は、minimumFractionDigits と ISO 4217 通貨コードリストで提供される下位単位の桁数(リストに情報がない場合は 2)の大きい方です。パーセント形式の既定値は、minimumFractionDigits と 0 の大きい方です。
minimumSignificantDigits
有効数字の最小桁数を表す数値。値: 1~21。既定値: 1。
maximumSignificantDigits
有効数字の最大桁数を表す数値。値: 1~21。既定値: 21。

プロパティ minimumFractionDigitsmaximumFractionDigitsminimumSignificantDigitsmaximumSignificantDigits は 2 つのグループに分けられます。

第 2 のグループで 1 つでもプロパティが定義されると、第 1 のグループは無視されます。

DA=new Intl.PluralRules('ja');  //日本語。
D=DA.select(0);  //=[string]:other
D=DA.select(1);  //=[string]:other
D=DA.select(2);  //=[string]:other
DA=new Intl.PluralRules('ja', {type:'ordinal'});  //日本語、種別。
D=DA.select(0);  //=[string]:other
D=DA.select(1);  //=[string]:other
D=DA.select(2);  //=[string]:other
DA=new Intl.PluralRules('en');  //英語。
D=DA.select(0);  //=[string]:other
D=DA.select(1);  //=[string]:one
D=DA.select(2);  //=[string]:other
DA=new Intl.PluralRules('en', {type:'ordinal'});  //英語、種別。
D=DA.select(0);  //=[string]:other
D=DA.select(1);  //=[string]:one
D=DA.select(2);  //=[string]:two
DA=new Intl.PluralRules('ar');  //アラビア語。
D=DA.select(0);  //=[string]:zero
D=DA.select(1);  //=[string]:one
D=DA.select(2);  //=[string]:two
D=DA.select(10);  //=[string]:few
D=DA.select(14);  //=[string]:many
new Intl.NumberFormat('ar', {maximumSignificantDigits:1});
D=DA.format(14);  //=[string]:10
	//↑「10」に四捨五入される。
DA=new Intl.PluralRules('ar', {maximumSignificantDigits:1});  //アラビア語、数値の有効桁数:1桁。
D=DA.select(14);  //=[string]:few

select()

Intl.NumberFormat()format()


テスト