テンプレート:Convert
編集する方へ: テンプレート本体をカテゴリに入れず、代わりに解説ページの
<includeonly></includeonly>
内に記述してください。ウィキボヤージュで測定値を使うには
編集変換テンプレートの使い方
編集{{convert}} テンプレートは、片方の単位系(任意に指定)から別の単位系へ自動計算して 変換し、その結果を表示する 働きをします。例をあげます。
{{convert|2|km|mi}}
→ 2 kilometres (1.2 mi){{convert|7|mi|km}}
→ 7 miles (11 km)
書式は複数あり、また計算精度は以下の通りです。
単位名または記号(略語):1ポンド か1 lb か?
編集既定では最初の値は単位名を、2番目の値は記号(略語)を示します。
「キロメートル」のように単位名を明示するか、略号「km」にするのか。テンプレートのスイッチ部分 |abbr=on/off
を使うと、以下のように切り替わります。縦棒記号「|」の右側を入れ替えてみましょう。
{{convert|1|lb|kg}}
→ 1 pound (0.45 kg)(比較のためのサンプル。ポインド・キログラム換算の最初の値を入れ替えてみた。){{convert|1|lb|kg|abbr=on}}
→ 1 lb (0.45 kg) スイッチをon に指定。単位が略号になる。{{convert|1|lb|kg|abbr=off}}
→ 1 pound (0.45 kilograms) スイッチをoff に指定。単位名を文字列として示す。
|abbr=in
スイッチが「in」の場合は既定で「off」の挙動を切り替えます。(|abbr=out
)
{{convert|1|lb|kg|abbr=in}}
→ 1 lb (0.45 kilograms) スイッチをin に指定。換算の左辺は略号、右辺が文字列に変わった。
形容詞形にする場合:10マイルの距離
編集形容詞形(「●●の」)を作るには、|adj=on
と書いて引数「adj」をonにします。違いを比較しましょう。
{{convert|10|mi|km}} を行く
→ 10 miles (16 km) を行く。(既定と比較){{convert|10|mi|km|adj=on}} の距離
→ 10-mile (16 km) の距離。(数値と単位の間に半角のハイフンが挟まった。)
概数:100 ft の概数は 30 m か30.5 m か30.48 m ?
編集これは100 feet (30,480 mm)を使った場合について述べています。実際にはメートル法の数値は概数を使う場合が大半です。その方法を複数、ご紹介しましょう。
数の既定の丸め方
編集- 既定では、換算の入力値に対応する精度とは出力値を丸めるか(小数点以下のケタ数—もしくはマイナスの数値なら小数点より前の任意の数のゼロの数—を乗算する変換なら、係数が0.02以上0.2以下なら1増、0.2以上2未満なら変わらず、2以上20未満なら1減など)、または有効数字2桁か、どちらかより正確な方を採用します。例外があり、「温度の概数」です(下記を参照)。
概数の例 | ||
---|---|---|
入力値 | 表示 | 備考 |
{{convert|123|ft|m|-1}} | 123 feet (40 m) | |
{{convert|123|ft|m|0}} | 123 feet (37 m) | |
{{convert|123|ft|m|1}} | 123 feet (37.5 m) | |
{{convert|550|ft|m|0}} | 550 feet (168 m) | 概数は167.64 m |
{{convert|550|ft|m}} | 550 feet (170 m) | 概数は170、あるいは167.64 m |
{{convert|500|ft|m|0}} | 500 feet (152 m) | 概数は152.4 m |
{{convert|500|ft|m}} | 500 feet (150 m) | 概数は150、あるいは152.4 m |
変換 テンプレートが対応する数の丸め方には4種類あります。
精度を指定して表示:|precision=
を適用
編集
4番目の名前のないパラメーター(「convert to」(変換先)パラメーターが省略された場合は3番目の名なしのパラメーター、範囲を指定した場合は同5番目、範囲を指定し「convert to」を省略した場合は再度、同4番目のパラメーターを指定し、目指す「precision」(精度)を指定)は省略されます。「精度」という名前のパラメータに置き換える必要があります)。 変換は、この数値の 1/10 乗に最も近い値に四捨五入されます。たとえば結果が 8621 で概数が「-2」の場合、出力値は 8600 です。出力値がが「234.0283043」で概数が「0」の場合、出力値は 234 になります。
ある特定の数字の倍数を表示:|sigfig=
を適用
編集
出力の数字を有効数字「n」で指定するには、次を使用します。|sigfig=<number>
:
- 比較対象: {{convert|1200|ft|m}} → 1,200 feet (370 m)
- {{convert|1200|ft|m|sigfig=4}} → 1,200 feet (365.8 m)
- {{convert|1200|ft|m|sigfig=3}} → 1,200 feet (366 m)
- {{convert|1200|ft|m|sigfig=2}} → 1,200 feet (370 m)
- {{convert|1200|ft|m|sigfig=1}} → 1,200 feet (400 m)
もし|sigfig=
を設定しても無効です
- {{convert|1200|ft|m|sigfig=0}} → 1,200 feet (370 m)*
5の倍数を表示:15、20、25 など
編集|round=5
を使い、出力を5の倍数で表示します。
{{convert|10|m|ft}}
→ 10 metres (33 ft){{convert|10|m|ft|round=5}}
→ 10 metres (35 ft)
似たケース:|round=25
を使い、出力を25の倍数で表示。
{{convert|10|m|ft}}
→ 10 metres (33 ft){{convert|10|m|ft|round=25}}
→ 10 metres (25 ft)- 比較対象:
{{convert|10|m|ft|sigfig=4}}
→ 10 metres (32.81 ft)
範囲内では「各値」を個別の値に丸めることができます。|round=each
を使った場合:
{{convert|10 x 200 x 3000|m|ft}}
→ 10 by 200 by 3,000 metres (33 ft × 656 ft × 9,843 ft){{convert|10 x 200 x 3000|m|ft|round=each}}
→ 10 by 200 by 3,000 metres (33 ft × 660 ft × 9,800 ft)
分数の倍数を概数で示す:2 3/16 inch
編集|frac=<正の整数>
を使って、目的の「分母」を指定します。(分母はスラッシュの右側の数字。たとえば1/3 の 3)。
{{convert|5.56|cm|in|frac=16}}
→ 5.56 centimetres (2 3⁄16 in){{convert|8|cm|in|frac=4}}
→ 8 centimetres (3 1⁄4 in)
可能な場合は端数を縮めます:
{{convert|8|cm|in|frac=100}}
→ 8 centimetres (3 3⁄20 in)
{{convert|8|cm|in}}
→ 8 centimetres (3.150 in)(比較の対象)
温度を複数の単位の概数で表示、°C、°F、K
編集温度の場合、変換は入力値の精度と同等の精度、またはケルビンで表現した場合には有効数字3桁から得る精度のいずれか、より正確な方に丸められます。
{{convert|10|C|F K}}
→ 10 °C (50 °F; 283 K)
注記
- 温度の「差」の場合、たとえば「20°Cの上昇」の変換には
|C-change=20
&tc を使用します。 {{convert|20|C-change|F-change K-change}}
→ A rise of 20 °C (36 °F; 20 K)
- 比較対象:「温度20 °C」の出力:温度は 20 °C (68 °F; 293 K) となります。
複数の単位系で表示:10 °C (50 °F; 283 K)
編集Separate the multiple output units by a space:
{{convert|10|C|F K}}
→ 10 °C (50 °F; 283 K){{convert|5|km|mi nmi}}
→ 5 kilometres (3.1 mi; 2.7 nmi)
幅のある値を表示
編集特定の範囲:6 から 17 kg(13 から 37 lb)
編集Range indicators are entered as the second parameter (between the values). Range separators can be:
テンプレート:Convert/doc/range separator list
倍数:6 m × 12 m (20 ft × 39 ft)
編集- Use "by"
{{convert|6|by|12|ft|m}}
→ 6 by 12 feet (1.8 by 3.7 m)- Use "×" or ""x""
{{convert|6|x|12|m|ft}}
→ 6 by 12 metres (20 ft × 39 ft)
In science, the formal way is to set |x|
and |abbr=on
(keeping dimensions right, like in area = x km2):
{{convert|6|x|12|m|ft|abbr=on}}
→ 6 m × 12 m (20 ft × 39 ft)
フィート、インチ の範囲、倍数
編集While it is possible to enter feet, inch in a simple conversion, this is not possible for ranges:
{{convert|1|ft|3|in|mm}}
→ 1 foot 3 inches (380 mm) (to compare){{convert|1|ft|3|in|x|3|ft|5|in|mm}}
→ 1 foot 3 inches ([convert: unknown unit])*
用語
編集単位名を文字列として表示:英国式の metre かアメリカ式の meter か?
編集Default spelling of units is the British metre. To show the American spelling, use |sp=us
:
{{convert|1|m|ft}}
→ 1 metre (3.3 ft) -- default{{convert|1|m|ft|sp=us}}
→ 1 meter (3.3 ft)
数字を欧文でつづる:ten miles
編集文字列を加える:4 planted acres
編集?耕地面積4エーカー
- 不完全な区切り Incomplete section
{{convert|4|acre||adj=pre|planted}}
→ 4 planted acres (1.6 ha)
副詞を加える:A 10-foot-long corridor
編集?
{{convert|4|ft|m|adj=mid|-long}}
→ 10-foot-long (3.0 m)
文法型:18-、24-、32-ポンド砲(8、11、15 kg砲)
編集- "アメリカの防衛軍は18-、24-、32-ポンド砲を装備(8, 11 15 kg)。"
この書式は、単に変換テンプレート {{convert}} を使っても、出力できません。実現するには3段階を設けます。
- Step 1: Enter the input numbers and units in {{convert}} just to get the calculated output:
had {{convert|18 |, |24 |, |32 |lb |kg |0 }} cannons
- → had 18, 24, 32 pounds (8, 11, 15 kg) cannons
- The core conversion should look good now. You can save this (or preview).
- Step 2: We need the resulting text in plain code in the page, not as a {{convert}} template.
- For this, add
subst:
to the template name (for 'substitute') :had {{subst:convert|18 |, |24 |, |32 |lb |kg |0 }} cannons
- As a check: the preview result should show the conversion correct, with the numbers still right.
- Now save this.
- → had 18, 24, 32 pounds (8, 11, 15 kg) cannons
- Step 3: When opening the edit screen again, you'll see that the text is there in code. The template {{convert}} itself has disappeared. You can change the text as needed. The edit screen text is:
had 18, 24, 32 pounds (8, 11, 15 kg) cannons
- You can edit this text to add the grammar:
had 18-,_24-_and_32-pounder (8, 11_and_15 kg) cannons
- After saving your edit, it shows:
- → "had 18-, 24- and 32-pounder (8, 11 and 15 kg) cannons".
数値
編集接頭詞 SI を添える:gigameter (Gm) かmicrometer (μm) か
編集Units can have an SI prefix like G
before the unit: Gm
, and giga
before the name: gigameter
. These are plain multiplication factors.
To illustrate, these are trivial calculations (from meter to meter), showing the multiplication factor:
- 12 Gm (1.2×1010 m)
- 12 μm (1.2×10−5 m)
The prefix can be added before the SI unit (here: unit m
for meter):
{{convert|12|Gm|mi|abbr=on}}
→ 12 Gm (7,500,000 mi)Mm
: 12 Mm (7,500 mi)km
: 12 km (39,000 ft)mm
: 12 mm (0.47 in)μm
: 12 μm (0.012 mm)um
: 12 μm (0.012 mm) (letter "u" can be used for "μ" here)
The prefix can be used in the output unit:
{{convert|12000|mi||Mm|abbr=on}}
→ 12,000 mi (19 Mm){{convert|12|in|μm|abbr=on}}
→ 12 in (300,000 μm)
As an exception, the non-SI unit "inch" can have the "μ" prefix too)
{{convert|12|μm|μin|abbr=on}}
→ 12 μm (470 μin)
千単位の区切り:1,000 mi and 1000 mi
編集In input, a comma for thousands separator is accepted. A gap (space) is not. In output, by default, the thousand separator is the comma:
{{convert|1,234,567|m|ft}}
→ 1,234,567 metres (4,050,417 ft){{convert|1,234,567|m|ft}}
→ 1,234,567 metres (4,050,417 ft){{convert|1 234 567|m|ft}}
→ [convert: 無効な番号]
Set |comma=off
to remove the separator:
{{convert|1234567|m|ft|comma=off}}
→ 1,234,567 metres (4,050,417 ft)*
Use |comma=gaps
to set digit grouping by gap (<space>
) in larger numbers (thousands separator):
{{convert|1234567|m|ft}}
→ 1,234,567 metres (4,050,417 ft) (To compare, default){{convert|1234567|m|ft|comma=gaps}}
→ 1234567 metres (4050417 ft)
Setting |comma=5
or |comma=gaps5
will only add the separator when the number of digits is 5 or more:
{{convert|1234|m|ft}}
→ 1,234 metres (4,049 ft) (To compare, default){{convert|1234|m|ft|comma=5}}
→ 1234 metres (4049 ft){{convert|1234567|m|ft|comma=5}}
→ 1,234,567 metres (4,050,417 ft){{convert|1234|m|ft|comma=gaps5}}
→ 1,234 metres (4,049 ft)*{{convert|1234567|m|ft|comma=gaps5}}
→ 1,234,567 metres (4,050,417 ft)*
出力結果を操作する
編集カッコ記号と区切り子:10 m [33 ft]
編集Punctuation that distinguishes the two measurements is set by |disp=
.
Options are: b
(the default), sqbr
, comma
, or
, br
, x|...
:
{{convert|10|m|ft}}
→ 10 metres (33 ft) -- ( ) brackets are the default{{convert|10|m|ft|disp=sqbr}}
→ 10 metres [33 ft]{{convert|10|m|ft|disp=comma}}
→ 10 metres, 33 ft{{convert|10|m|ft|disp=or}}
→ 10 metres or 33 feet
Setting |disp=br
will force a new line (<br>
)
{{convert|10|m|ft|disp=br}}
→ 10 metres
33 feet
Setting |disp=x|...
allows any text as separator:
{{convert|10|m|ft|disp=x|_MyText_}}
→ 10 metres_MyText_33 ft -- (To display spaces, use
)
測定値2件を入れ替え(並べ替え):1,609.3 metres (1 mile)
編集Setting |order=flip
will flip (swap) the two measurements:
{{convert|1|mi|m}}
→ 1 mile (1,609.3 metres) (To compare, default){{convert|1|mi|m|order=flip}}
→ 1,609.3 metres (1 mile)
When converting to multiple units, the effect is:
{{convert|10|km|mi nmi|order=flip}}
→ 6.2137 miles; 5.3996 nautical miles (10 kilometres){{convert|10|km|nmi mi|order=flip}}
→ 5.3996 nautical miles; 6.2137 miles (10 kilometres)
結果の一部のみ表示:2 (1.5)
編集It is possible to display only parts of the conversion result:
Convert | Output | Description |
---|---|---|
{{convert|2|cuyd|m3}} | 2 cubic yards (1.5 m3) | Default, to compare |
{{convert|2|cuyd|m3|abbr=values}} | 2 (1.5) | Input and output numbers |
{{convert|2|cuyd|m3|disp=unit}} | cubic yards | Input unit |
{{convert|2|cuyd|m3|disp=unit|adj=on}} | cubic-yard | Input unit, adjective (hyphenated) |
{{convert|2|cuyd|cuyd|0|disp=out|abbr=off}} | 2 cubic yards | Input (workaround) |
{{convert|2|cuyd|m3|disp=unit2}} | m3 | Output unit (symbol) |
{{convert|2|cuyd|m3|disp=unit2|abbr=off}} | cubic metres | Output unit (name) |
{{convert|2|cuyd|m3|disp=number}} | 1.5 | Output value |
{{convert|2|cuyd|m3|disp=out}} | 1.5 m3 | Output value and unit |
{{convert|2|cuyd|m3|disp=out|abbr=off}} | 2 cubic yards (1.5 m3)* | Output value and unit |
対応表のオプション
編集For the wikitable structure, there are two options: split over columns and make the table sortable.
Show numbers only in columns in a table
編集Using {convert} in a table cell, with |disp=table
splits the result over two columns:
{{convert|10|m|ft|disp=table}}
→ style="text-align:right;"|10
|33
|disp=tablecen
does the same, and also centers the text:
{{convert|20|m|ft|disp=tablecen}}
→ style="text-align:center;"|20
|66
The units are added as a column header:
m ft |disp=table
10 33 |disp=tablecen
20 66 |disp=<other>
(default)30 metres (98 ft)
並べ替え
編集- Use both
|disp=table
|sortable=on
to produce table columns (pipe symbols), with sortable table column. As of January 2013, only the first (lefthand) column will sort (improvements pending).
- {{convert|10|m|ft|disp=table|sortable=on}} →
- This shows the hidden numerical sortkey:
align="right"|<span style="display:none">7001100000000000000</span>10 |align="right"|33
m ft 15 3⁄4 52 15.5 51 16.0 52.5 16 52
パラメータの一覧
編集{{convert}}のオプション引数 | |||
---|---|---|---|
オプション | 説明 | 備考 | |
|abbr=in |
Use symbol for first (left-hand side) unit | Symbol ('abbreviation') | |
|abbr=off |
Use name for all units | Symbol ('abbreviation') | |
|abbr=none | |||
|abbr=on |
Use symbol for all units | Symbol ('abbreviation') | |
|abbr=out |
Use symbol for right-hand side unit (default) | Symbol ('abbreviation') | |
|abbr=values |
Show only input and output numbers, not units | Parts only | |
|adj=1 |
Unit name is singular when number is 1 or less, but not zero | Grammar, plural | |
|adj=j |
Join number and unit name using " " instead of a space | Join values | |
|adj=mid|x=... |
User-specified text after the input unit; sets adj=on (adjective) |
Word adding, adjective | |
|adj=on |
Unit name is adjective (singular and hyphenated) | Grammar, adjective | |
|adj=pre|x=... |
User-specified text before input unit | Word adding | |
|adj=ri0 |
Round input with precision 0 | Rounding and sigfig | |
|adj=ri1 |
Round input with precision 1 | Rounding and sigfig | |
|adj=ri2 |
Round input with precision 2 | Rounding and sigfig | |
|adj=ri3 |
Round input with precision 3 | Rounding and sigfig | |
|disp=b |
Join input and output using " (...)" (default) | Join values | |
|disp=sqbr |
Join input and output using " [...]" | Join values | |
|disp=br |
Join input and output using "<br/>" | Join values | |
|disp=comma |
Join input and output using ", " | Join values | |
|disp=or |
Join input and output using " or " | Join values | |
|disp=number |
Display output number only | Parts only | |
|disp=output number only | |||
|disp=out |
Display only output number and name/symbol | Parts only | |
|disp=output only | |||
|disp=preunit|x=... |
User-specified text before input and output units | Word adding | |
|disp=table |
Output is suitable for a table cell with align="right" | Table columns | |
|disp=tablecen |
Output is suitable for a table cell with align="center" | Table columns | |
|disp=unit |
Display input name/symbol only ( not input number, not output) | Parts only | |
|disp=unit2 |
Display output name/symbol only (not input; not output number) | Parts only | |
|disp=x|... |
Join input and output using user-specified text | Word adding | |
|comma=5 |
Only use comma for thousands separator if 5 or more digits | Number format | |
|comma=gaps |
Use gaps (space), not comma, for thousands separator | Number format | |
|comma=gaps5 |
Use gaps (space), but only if 5 or more digits | Number format | |
|comma=off |
No thousands separator | Number format | |
|frac=N |
Show imperial number in fractions, denominator=N | Number format, fraction | |
|lk=in |
Link left-hand side unit name or symbol | Unit link | |
|lk=on |
Link all unit names or symbols (but not twice for the same unit) | Unit link | |
|lk=out |
Link right-hand side unit name or symbol | Unit link | |
|order=flip |
Inverts order of input, output measurements (conversion first) | Order | |
|round=5 |
Rounds calculation to the nearest multiple of 5 | Rounding and sigfig | |
|round=25 |
Rounds calculation to the nearest multiple of 25 | Rounding and sigfig | |
|round=each |
In a range, each number is rounded by the default rounding | Rounding and sigfig | |
|sigfig=N |
Round output number to N significant figures (N is a positive integer) | Rounding and sigfig | |
|sortable=in |
Output numeric hidden sort field for use in a sortable table (based on input) | Table sort | |
|sortable=on | |||
|sortable=out |
Output numeric hidden sort field for use in a sortable table (based on output) | Table sort | |
|sp=us |
Use U.S. spelling (like "meter" instead of default "metre") | Spelling U.S. names | |
|spell=in |
Spell input number in words | Spelling numbers | |
|spell=In |
Spell input number in words with first letter uppercase | Spelling numbers | |
|spell=on |
Spell input and output numbers in words | Spelling numbers | |
|spell=On |
Spell input and output numbers in words with first letter uppercase | Spelling numbers | |
|$=€ |
Replace $-sign with a currency sign, for example in $/acre テンプレート:Nowrap |
Cost per unit | |
|debug=yes |
Debugging only. In a sortable table: show the normally hidden sort key | Table sort |
TemplateData
編集Converts measurements to other units.
パラメーター | 説明 | 型 | 状態 | |
---|---|---|---|---|
Value | 1 | The value to convert. | 数値 | 必須 |
From unit | 2 | The unit for the provided value.
| 文字列 | 必須 |
To units | 3 | The units to convert into. Separate units by a space for multiple outputs. In an output unit, use + for a multiplication space.
| 文字列 | 推奨 |
Precision or suffix | 4 | Significant digits after decimal dot or, if negative, exponent of ten. | 数値 | 省略可能 |
Link units | lk | Indication of what units to apply wikilinks to. Use “on” for all, “in” for the input unit, “out” for the output units, or “off” for none of the units. For more fine-grained control over which units to link, use the template multiple times.
| 文字列 | 省略可能 |
Abbreviation | abbr | Display for the units: “on” to display all units using their unit symbols, “off” to display all units in full words, “in” to display the unit symbol for the input unit, “out” to display the unit symbols for the output units, “unit” to display unit symbols for both input and output units when using scientific notation, “values” for no units at all (neither unit symbols nor full words of units).
| 文字列 | 推奨 |
Spelling | sp | Spelling of units. Use “us” to display unit names using U.S. spelling.
| 文字列 | 省略可能 |
Adjective | adj | Whether to use adjectival form. Use “on” for singular unit name appended by a hyphen, “mid” to put conversion at end, or “off” (default) for no adjectival form.
| ウィキテキストの一部 | 省略可能 |
Conversion | disp | Display conversion result: “or”: after ‘or’, “x”: with custom prefix and suffix, “b”: in parentheses, “table”/“tablecen”, “output only”: alone, “output number only”: alone and without unit, “unit”: not at all but input unit; if the value is a number it is used as precision.
| 文字列 | 省略可能 |
Ordering | order | “flip” returns converted value first, input value second.
| 文字列 | 省略可能 |
Significant figures | sigfig | Indicates the number of significant figures to be used in rounding. | 数値 | 省略可能 |
Rounding output | round | The type of rounding. “5” rounds the output number to nearest multiple of 5, “25” to nearest multiple of 25, “each” rounds each number in a range. | 数値 | 省略可能 |
Thousands separator | comma | Sets or suppresses the use of thousands separators in the numbers. “off”: no separator; “gaps”: use space instead of comma as thousands separator; “5”: only add thousands separator when the integral part of the number uses 5 positions or more (10,000 or more; if using comma as thousands separator, 1234 would produce '1234', 12345 would produce '12,345').
| ブール値 | 省略可能 |
Sort key | sortable | “on” generates a hidden sort key
| ブール値 | 省略可能 |
Spell numbers? | spell | If used, spells input or input and output numbers in words, optionally capitalizing the first
| 文字列 | 省略可能 |
Singular? | sing | If 'yes', uses singular form of units (deprecated)
| ブール値 | 非推奨 |
Fraction? | frac | fraction as rounding unit | 数値 | 省略可能 |
Currency symbol | $ | sets currency symbol in both units
| 文字列 | 省略可能 |
Mach altitude (ft) | altitude_ft | Mach (speed) depends on altitide
| 数値 | 省略可能 |
Mach altitude (m) | altitude_m | Mach (speed) depends on altitude | 数値 | 省略可能 |
WD property | input | Reads the property value of the item (article), then converts it
| 文字列 | 省略可能 |