JavaScript

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


編集:2023.01.10 by T.A.

[Edge]。→

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

構文
new Intl.NumberFormat([locales[, options]])
表示例「」内のフォントは「MS ゴシック」
locales 省略可 言語タグを持つ文字列、またはそのような文字列の配列。→Intl:locales

次の Unicode 拡張が可能です。

キー:
nu
数値表記方法を表す文字列。→Numbering System

→¶ numberingSystem プロパティからも利用できます。

options 省略可。以下のようなプロパティと値を 1 つ以上持つオブジェクト。
compactDisplay
コンパクト表示を表す文字列。notation が "compact" の場合のみ可能。値は以下の何れか。
short (既定値)
long
currency
どこの国の通貨かを表す文字列(通貨コード)。値:→

style の指定が必要であり、style の値が "currency" の場合に必要な指定。

値例:
EUR ユーロ。

例: 「€12,345.68」('ja', {currency:'EUR', style:'currency'})

JPY 日本円。

例: 「¥12,346」('ja', {currency:'JPY', style:'currency'})

USD アメリカ合衆国ドル。

例: 「$12,345.68」('ja', {currency:'USD', style:'currency'})

currencyDisplay
通貨の表示書式を表す文字列。値は以下の何れか。
DA=new Intl.NumberFormat(○○);
D=DA.format(12345.6789);
symbol 地域化された通貨記号。例えば「€」など。(既定値)

D: 「¥12,346」('ja', {currencyDisplay:'symbol', currency:'JPY', style:'currency'})

D: 「$12,345.68」('ja', {currencyDisplay:'symbol', currency:'USD', style:'currency'})

narrowSymbol 短い形式の記号。

D: 「¥12,346」('ja', {currencyDisplay:'narrowSymbol', currency:'JPY', style:'currency'})

D: 「$12,345.68」('ja', {currencyDisplay:'narrowSymbol', currency:'USD', style:'currency'})

code ISO 通貨コード。

D: 「JPY 12,346」('ja', {currencyDisplay:'code', currency:'JPY', style:'currency'})

name 地域化された通貨名。

D: 「12,346円」('ja', {currencyDisplay:'name', currency:'JPY', style:'currency'})

D: 「12,345.68米ドル」('ja', {currencyDisplay:'name', currency:'USD', style:'currency'})

D: 「12,345.68 US dollars」('en', {currencyDisplay:'name', currency:'USD', style:'currency'})

currencySign
通貨表示でのマイナス値の時の表示方法を表す文字列。値は以下の何れか。
DA=new Intl.NumberFormat(○○);
D=DA.format(-12345.6789);
standard 標準。(既定値)

D: 「-¥12,346」('ja', {currencySign:'standard', currency:'JPY', style:'currency'})

accounting 会計。大概、括弧「( )」で括る。

D: 「(¥12,346)」('ja', {currencySign:'accounting', currency:'JPY', style:'currency'})

localeMatcher
使用するロケール比較アルゴリズムを表す文字列。値は以下の何れか。
lookup
best fit (既定値)

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

notation
数値を表示する書式を表す文字列。値は以下の何れか。
DA=new Intl.NumberFormat(○○);
D=DA.format(12345.6789);
standard 通常の数値の書式。(既定値)

D: 「12,345.679」('ja', {notation:'standard', currency:'JPY', style:'currency'})

scientific 指数表示

D: 「¥1E4」('ja', {notation:'scientific', currency:'JPY', style:'currency'})

D: 「1.235E4」('ja', {notation:'scientific'})

engineering エンジニア向け。

D: 「12.346E3」('ja', {notation:'engineering'})

compact 簡易表示。

D: 「1.2万」('ja', {notation:'compact'})

numberingSystem
数値の体系を表す文字列。値は以下の何れか。→Numbering System
DA=new Intl.NumberFormat(○○);
D=DA.format(12345.6789);
arab

D: 「١٢٬٣٤٥٫٦٧٩」('ja', {numberingSystem:'arab'})

arabext
bali
beng
deva
fullwide
gujr
guru
hanidec
khmr
knda
laoo
latn
limb
mlym
mong
mymr
orya
tamldec
telu
thai
tibt

→Unicode 拡張キー nu からも利用できます。

signDisplay
数値の符号を表示する時を表す文字列。値は以下の何れか。
DA=new Intl.NumberFormat(○○);
D=DA.format(□□);
auto 負の数のみ。(既定値)

D: 「12,345.679」('ja', {signDisplay:'auto'}、12345.6789)

D: 「-12,345.679」('ja', {signDisplay:'auto'}、-12345.6789)

never 符号を表示しない。

D: 「12,345.679」('ja', {signDisplay:'never'}、-12345.6789)

always 常に表示。

D: 「+12,345.679」('ja', {signDisplay:'always'}、12345.6789)

exceptZero ゼロ以外の時に表示。

D: 「+12,345.679」('ja', {signDisplay:'exceptZero'}、12345.6789)

D: 「0」('ja', {signDisplay:'exceptZero'}、-0)

style
書式化スタイルを表す文字列。値は以下の何れか。
DA=new Intl.NumberFormat(○○);
D=DA.format(□□);
decimal 普通の数値。(既定値)

D: 「12,345.679」('ja', {style:'decimal'}、12345.6789)

currency 通貨。

D: 「¥12,346」('ja', {style:'currency', currency:'JPY'}、12345.6789)

percent パーセント。

D: 「1,234,568%」('ja', {style:'percent'}、12345.6789)

D: 「12%」('ja', {style:'percent'}、0.12345)

unit 単位。unit プロパティの指定が必要。

D: 「12,345.679 byte」('ja', {style:'unit', unit:'byte'}、12345.6789)

unit
style プロパティで unit を指定した場合に使用する単位を表す文字列。既定値は無し。→
DA=new Intl.NumberFormat(○○);
D=DA.format(12345.6789);
説明
acre エーカー(面積)

D: 「12,345.679 ac」('ja', {style:'unit', unit:'acre'})

bit ビット

D: 「12,345.679 bit」('ja', {style:'unit', unit:'bit'})

byte バイト

D: 「12,345.679 byte」('ja', {style:'unit', unit:'byte'})

celsius セルシウス度(温度)

D: 「12,345.679°C」('ja', {style:'unit', unit:'celsius'})

centimeter センチメートル(長さ)

D: 「12,345.679 cm」('ja', {style:'unit', unit:'centimeter'})

day 「日」

D: 「12,345.679 日」('ja', {style:'unit', unit:'day'})

degree デグリー(角度)

D: 「12,345.679 度」('ja', {style:'unit', unit:'degree'})

fahrenheit ファーレンハイト度(華氏度。温度)

D: 「12,345.679°F」('ja', {style:'unit', unit:'fahrenheit'})

fluid-ounce 液量オンス(体積?)

D: 「12,345.679 fl oz」('ja', {style:'unit', unit:'fluid-ounce'})

foot フット、フィート。(長さ)

D: 「12,345.679 ft」('ja', {style:'unit', unit:'foot'})

gallon ガロン(体積)

D: 「12,345.679 gal」('ja', {style:'unit', unit:'gallon'})

gigabit ギガ ビット

D: 「12,345.679 Gb」('ja', {style:'unit', unit:'gigabit'})

gigabyte ギガ バイト

D: 「12,345.679 GB」('ja', {style:'unit', unit:'gigabyte'})

gram グラム(重さ)

D: 「12,345.679 g」('ja', {style:'unit', unit:'gram'})

hectare ヘクタール(面積)

D: 「12,345.679 ha」('ja', {style:'unit', unit:'hectare'})

hour 時間

D: 「12,345.679 時間」('ja', {style:'unit', unit:'hour'})

inch インチ(長さ)

D: 「12,345.679 in」('ja', {style:'unit', unit:'inch'})

kilobit キロ ビット

D: 「12,345.679 kb」('ja', {style:'unit', unit:'kilobit'})

kilobyte キロ バイト

D: 「12,345.679 KB」('ja', {style:'unit', unit:'kilobyte'})

kilogram キロ グラム(重さ)

D: 「12,345.679 kg」('ja', {style:'unit', unit:'kilogram'})

kilometer キロ メーター(長さ)

D: 「12,345.679 km」('ja', {style:'unit', unit:'kilometer'})

liter リットル(体積)

D: 「12,345.679 L」('ja', {style:'unit', unit:'liter'})

megabit メガ ビット

D: 「12,345.679 Mb」('ja', {style:'unit', unit:'megabit'})

megabyte メガ バイト

D: 「12,345.679 MB」('ja', {style:'unit', unit:'megabyte'})

meter メートル(長さ)

D: 「12,345.679 m」('ja', {style:'unit', unit:'meter'})

mile マイル(長さ)

D: 「12,345.679 mi」('ja', {style:'unit', unit:'mile'})

mile-scandinavian スカンジナビア マイル(長さ)

D: 「12,345.679 smi」('ja', {style:'unit', unit:'mile-scandinavian'})

milliliter ミリ リットル(体積)

D: 「12,345.679 ml」('ja', {style:'unit', unit:'milliliter'})

millimeter ミリ メートル(長さ)

D: 「12,345.679 mm」('ja', {style:'unit', unit:'millimeter'})

millisecond ミリ秒(時間)

D: 「12,345.679 ms」('ja', {style:'unit', unit:'millisecond'})

minute 分(時間)

D: 「12,345.679 分」('ja', {style:'unit', unit:'minute'})

month 月数

D: 「12,345.679 か月」('ja', {style:'unit', unit:'month'})

ounce オンス(重さ)

D: 「12,345.679 oz」('ja', {style:'unit', unit:'ounce'})

percent パーセント(百分率)

D: 「12,345.679%」('ja', {style:'unit', unit:'percent'})

petabyte ペタ バイト(250 バイト)

D: 「12,345.679 PB」('ja', {style:'unit', unit:'petabyte'})

pound ポンド(重さ)

D: 「12,345.679 lb」('ja', {style:'unit', unit:'pound'})

second 秒(時間)

D: 「12,345.679 秒」('ja', {style:'unit', unit:'second'})

stone ストーン(重さ)

D: 「12,345.679 st」('ja', {style:'unit', unit:'stone'})

terabit テラ ビット(240 ビット)

D: 「12,345.679 Tb」('ja', {style:'unit', unit:'terabit'})

terabyte テラ バイト(240 バイト)

D: 「12,345.679 TB」('ja', {style:'unit', unit:'terabyte'})

week 週数

D: 「12,345.679 週間」('ja', {style:'unit', unit:'week'})

yard ヤード(長さ)

D: 「12,345.679 yd」('ja', {style:'unit', unit:'yard'})

year

D: 「12,345.679 年」('ja', {style:'unit', unit:'year'})

これらを "-per-" で結合して複合単位を作ることが可能:

D: 「12,345.679 km/L」('ja', {style:'unit', unit:'kilometer-per-liter'})

unitDisplay
unit の書式化で使用する単位のスタイルを表す文字列。値は以下の何れか。
DA=new Intl.NumberFormat(○○);
D=DA.format(12345.6789);
long

D: 「12,345.679 キロバイト」('ja', {style:'unit', unit:'kilobyte', unitDisplay:'long'})

short (既定値)

D: 「12,345.679 KB」('ja', {style:'unit', unit:'kilobyte', unitDisplay:'long'})

narrow

D: 「12,345.679KB」('ja', {style:'unit', unit:'kilobyte', unitDisplay:'narrow'})

useGrouping
書式化時に区切り記号を使用するかどうかを表す論理値。例えば、3 桁区切りなど。
DA=new Intl.NumberFormat(○○);
D=DA.format(12345.6789);
true 付ける。(既定値)

D: 「12,345.679」('ja', {useGrouping:true})

false 付けない

D: 「12345.679」('ja', {useGrouping:false})

minimumIntegerDigits
整数部の最小桁数を表す数値または文字列。値: 1~21。既定値: 1。
DA=new Intl.NumberFormat('ja', {minimumIntegerDigits:10});
D=DA.format(12345.6789);  //「0,000,012,345.679
minimumFractionDigits
小数部の最小桁数を表す数値または文字列。値: 0~20。

既定値: mdn: 通常の数値とパーセント形式では 0。通貨形式では ISO 4217 通貨コードリストで提供されている副単位の桁数です (このリストで情報が提供されていない場合は 2 です)。

DA=new Intl.NumberFormat('ja', {minimumIntegerDigits:10});
D=DA.format(12345.6789);  //「12,345.67890
DA=new Intl.NumberFormat('ja', {minimumFractionDigits:2});
D=DA.format(12345.6789);  //「12,345.679
maximumFractionDigits
小数部の最大桁数を表す数値または文字列。値: 0~20。

既定値: mdn: 通常の数値では minimumFractionDigits か 3 で大きい方。通貨形式では minimumFractionDigits と ISO 4217 通貨コードリストで提供されている副単位の桁数です (このリストで情報が提供されていない場合は 2)、パーセント形式の場合は minimumFractionDigits と 0 の大きい方です。

DA=new Intl.NumberFormat('ja', {maximumFractionDigits:2});
D=DA.format(12345.6789);  //「12,345.68
DA=new Intl.NumberFormat('ja', {maximumFractionDigits:5});
D=DA.format(12345.6789);  //「12,345.6789
DA=new Intl.NumberFormat('ja', {minimumFractionDigits:2, maximumFractionDigits:5});
D=DA.format(12345.6789);  //「12,345.6789」
D=DA.format(12345.6);  //「12,345.60」
D=DA.format(12345.678888);  //「12,345.67889
minimumSignificantDigits
数値の最小有効桁数を表す数値または文字列。値: 1~21。既定値: 1。
DA=new Intl.NumberFormat('ja', {minimumSignificantDigits:7});
D=DA.format(12345.6789);  //「12,345.6789」
D=DA.format(12345);  //「12,345.00
DA=new Intl.NumberFormat('ja', {minimumSignificantDigits:12});
D=DA.format(12345.6789);  //「12,345.6789000
maximumSignificantDigits
数値の最大有効桁数を表す数値または文字列。値は 1~21。既定値: 1。
DA=new Intl.NumberFormat('ja', {maximumSignificantDigits:7});
D=DA.format(12345);  //「12,345」
D=DA.format(12345.6789);  //「12,345.68
DA=new Intl.NumberFormat('ja', {maximumSignificantDigits:3});
D=DA.format(12345);  //「12,300

プロパティ(minimumFractionDigitsmaximumFractionDigitsminimumSignificantDigitsmaximumSignificantDigits)は 2 つのグループに分類できます。

2 つ目のグループで 1 つでもプロパティが定義されていれば、1 つ目のグループは無視されます。

DA=new Intl.NumberFormat('ja');  //日本語。
D=DA.format(12345.6789);  //=[string]:12,345.679
DA=new Intl.NumberFormat('en');  //英語。
D=DA.format(12345.6789);  //=[string]:12,345.679
DA=new Intl.NumberFormat('ar');  //アラビア語。
D=DA.format(12345.6789);  //=[string]:12,345.679

DA=new Intl.NumberFormat('ar-u-nu-arab');  //アラビア語の数値表記。
D=DA.format(12345.6789);  //=[string]:١٢٬٣٤٥٫٦٧٩

DA=new Intl.NumberFormat('ja', {currency:'JPY', currencyDisplay:'symbol', style:'currency'});  //日本語、日本円。
D=DA.format(12345.6789);  //=[string]:¥12,346
DA=new Intl.NumberFormat('ja', {currency:'JPY', currencyDisplay:'narrowSymbol', style:'currency'});  //日本語、日本円。
D=DA.format(12345.6789);  //=[string]:¥12,346
DA=new Intl.NumberFormat('ja', {currency:'JPY', currencyDisplay:'code', style:'currency'});  //日本語、日本円。
D=DA.format(12345.6789);  //=[string]:JPY 12,346
DA=new Intl.NumberFormat('ja', {currency:'JPY', currencyDisplay:'name', style:'currency'});  //日本語、日本円。
D=DA.format(12345.6789);  //=[string]:12,346円

DA=new Intl.NumberFormat('en', {currency:'USD', currencyDisplay:'narrowSymbol', style:'currency'});  //英語、アメリカドル、シンボル。
D=DA.format(12345.6789);  //=[string]:12,345.679
DA=new Intl.NumberFormat('en', {currency:'USD', style:'currency'});  //英語、アメリカドル、スタイル:通貨。
D=DA.format(12345.6789);  //=[string]:$12,345.68


テスト