[unchecked revision] | [checked revision] |
(Move doc from template page.) |
m (Add note about updating.) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{doc/start}} | {{doc/start}} | ||
<templatedata> | |||
{ | |||
"params": { | |||
"number": { | |||
"label": "Number", | |||
"type": "number", | |||
"description": "Numerical value to format for display with the unit.", | |||
"example": "2, -2, 3.45" | |||
}, | |||
"abbr": { | |||
"label": "Unit abbreviation", | |||
"description": "Case sensitive abbreviation of a unit of measure. If the abbreviation contains a forward slash \"/\" it may be replaced with the character \"p\".", | |||
"example": "m/s, mps, GHz, ppm, kg, m2, kWh", | |||
"type": "string" | |||
} | |||
}, | |||
"description": "Add a tooltip to an abbreviation of a unit of measure showing the actual name of the unit.", | |||
"format": "inline", | |||
"paramOrder": [ | |||
"number", | |||
"abbr" | |||
] | |||
} | |||
</templatedata> | |||
== Usage == | == Usage == | ||
* With a formatted number: {{tlx|Unit|''number''|''abbr''}} | |||
** If a number is specified, it is formatted with a space " " as a thousands separator and a period "." as the decimal separator. | |||
* With unit abbreviation only: {{tlx|Unit|''abbr''}} | |||
== New units == | |||
Recognized units are defined and documented in [[Module:Unit/data]]. | |||
== Examples == | == Examples == | ||
Line 10: | Line 39: | ||
! Code !! Result | ! Code !! Result | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|ppm}} || {{Unit|ppm}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|1200|m}} || {{Unit|1200|m}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|1|m/s}} || {{Unit|1|m/s}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|mps}} || {{Unit|mps}} | ||
|- | |- | ||
| {{tlx| | | 34 {{tlx|Unit|kg}} || 34 {{Unit|kg}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|+2|degc}} || {{Unit|+2|degc}} | ||
|} | |} | ||
Note that the abbreviation is case sensitive and special symbols are | Note that the abbreviation is case sensitive and if the unit contains special symbols they are displayed correctly: | ||
{| class="wikitable" | {| class="wikitable" | ||
|+ Various units. | |+ Various units. | ||
Line 29: | Line 58: | ||
! Code !! Result | ! Code !! Result | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|-2,1|mHz}} || {{Unit|-2,1|mHz}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|-0.1||MHz}} || {{Unit|-0.1|MHz}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|0|m2}} || {{Unit|0|m2}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|+1|kohm}} || {{Unit|+1|kohm}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|852001,99|kWh}} || {{Unit|852001,99|kWh}} | ||
|- | |- | ||
| {{tlx| | | 4–8 {{tlx|Unit|um}} || 4–8 {{Unit|um}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|J/(Kmol)}} || {{Unit|J/(Kmol)}} | ||
|} | |} | ||
If a unit definition is not found, the abbreviation (or text) is returned unchanged. | If a unit definition is not found, the abbreviation (or text) is returned unchanged. However, if the unit definition data is later ''updated'' to include the unit, it will begin using the tooltip correctly later. | ||
{| class="wikitable" | {| class="wikitable" | ||
|+ Invalid units. | |+ Invalid units. | ||
Line 50: | Line 79: | ||
! Code !! Result | ! Code !! Result | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|99|things}} || {{Unit|99|things}} | ||
|- | |||
| {{tlx|Unit|something/other}} || {{Unit|something/other}} | |||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|-2|players per hour}} || {{Unit|-2|players per hour}} | ||
|- | |- | ||
| {{tlx| | | {{tlx|Unit|7|lbft}} of torque || {{Unit|7|lbft}} of torque | ||
|- | |||
| {{tlx|Unit}} || {{Unit}} | |||
|} | |} | ||
== Modules == | == Modules == | ||
This template is using the following Modules: | This template is using the following Modules: | ||
*[[Module: | *[[Module:Unit]] | ||
{{doc/end}} | {{doc/end}} | ||
<includeonly>[[Category:Formatting templates]]</includeonly> |
Latest revision as of 15:26, 27 February 2022
Add a tooltip to an abbreviation of a unit of measure showing the actual name of the unit.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Number | number | Numerical value to format for display with the unit.
| Number | optional |
Unit abbreviation | abbr | Case sensitive abbreviation of a unit of measure. If the abbreviation contains a forward slash "/" it may be replaced with the character "p".
| String | optional |
Usage[edit source]
- With a formatted number:
{{Unit|number|abbr}}
- If a number is specified, it is formatted with a space " " as a thousands separator and a period "." as the decimal separator.
- With unit abbreviation only:
{{Unit|abbr}}
New units[edit source]
Recognized units are defined and documented in Module:Unit/data.
Examples[edit source]
Code | Result |
---|---|
{{Unit|ppm}} |
ppm |
{{Unit|1200|m}} |
1 200 m |
{{Unit|1|m/s}} |
1 m/s |
{{Unit|mps}} |
m/s |
34 {{Unit|kg}} |
34 kg |
{{Unit|+2|degc}} |
+2 °C |
Note that the abbreviation is case sensitive and if the unit contains special symbols they are displayed correctly:
Code | Result |
---|---|
{{Unit|-2,1|mHz}} |
-2.1 mHz |
{{Unit|-0.1|MHz}} |
-0.1 MHz |
{{Unit|0|m2}} |
0 m2 |
{{Unit|+1|kohm}} |
+1 kΩ |
{{Unit|852001,99|kWh}} |
852 001.99 kW⋅h |
4–8 {{Unit|um}} |
4–8 μm |
{{Unit|J/(Kmol)}} |
J/(K⋅mol) |
If a unit definition is not found, the abbreviation (or text) is returned unchanged. However, if the unit definition data is later updated to include the unit, it will begin using the tooltip correctly later.
Code | Result |
---|---|
{{Unit|99|things}} |
99 things |
{{Unit|something/other}} |
something/other |
{{Unit|-2|players per hour}} |
-2 players per hour |
{{Unit|7|lbft}} of torque |
7 lbft of torque |
{{Unit}} |
ERROR: No value given to Unit template! |
Modules[edit source]
This template is using the following Modules: