Modul:Val/units/dok

Fra Wikipedia, den frie encyklopædi

Defining a unit[rediger kildetekst]

A unit used in {{val}} can be defined on this page, or in {{convert}}; if not defined, the unit is used as entered.

Template:Val/list shows how to preview changes made while editing this page.

Units on this page may be entered under:

  • local builtin_units for normal units, or under
  • local builtin_units_long_scale for long scale units.

An entry defining a unit is a single line containing the unit code followed by two or more spaces, then the unit symbol followed by at least one tab character or two spaces, then the title of the article for a link if needed. The unit code must be followed by two spaces; the two spaces can be followed by any number of spaces or tab characters.

For example, the following defines a unit with code c, symbol c, and link Speed of light.

c                  ''c''            Speed of light

The code is used in val to identify the unit:

  • {{val|0.891|u=c}}0.891 c
  • {{val|0.891|ul=c}}0.891 c

A scale may be entered following the link. For example, the following defines a unit with code billion, symbol billion, link 1,000,000,000, and scale 1e9 (1×109). The scale affects the hidden sort key included in the result: for example, {{val|2|u=billion}} would sort after {{val|98.7|e=3}}.

billion            billion          1,000,000,000          1e9

A code may be defined as an alias of a unit known to {{convert}}. The following defines degC to refer to the unit known as °C in convert. There is no link because a link is defined in convert.

degC               °C               ALIAS

A unit may be defined as "SI" which means that the unit code begins with an SI prefix which will be interpreted by {{convert}}. For example, the following defines an SI unit with code kV, base symbol V, and link Volt. The symbol V refers to the base unit with the SI prefix removed. A unit defined in this manner will have its sort key scaled by convert according to the SI prefix: for example, {{val|1|u=kV}} would sort after {{val|999|u=V}}. This is useful for units which are not defined in convert, or which are defined but where a link different from that specified in convert is wanted.

kV                 V                Volt                   SI

Flag words can be entered after a tab character or two or more spaces:

  • ALIAS specifies that the unit's symbol is the code for a unit defined in {{convert}}}.
  • ANGLE identifies the unit as an "angle" so the unit is displayed after the number and uncertainty values; ANGLE also implies NOSPACE.
  • NOSPACE prevents the default insertion of a non-breaking space before the unit symbol.
  • SI specifies that the unit's symbol is for a base unit after removing the SI prefix in the unit code.