Skabelon:Val

Fra Wikipedia, den frie encyklopædi
Spring til navigation Spring til søgning
Documentation icon Skabelondokumentation[vis] [redigér] [historik] [opfrisk]
Information icon.svgDenne skabelon indeholder en eller flere valgbare parametre.
Skabelonen anvender en syntaks, som er yderst kompliceret og esoterisk. Forsøg ikke at ændre den, medmindre du er helt sikker på, at du forstår opbygningen og er indstillet på at udbedre alle eventuelle uheldige følger af, at ændringer giver et uventet resultat. Alle eksperimenter bør udføres i sandkassen, sandkasse-skabelonen, eller på din egen brugerside.

This template is used to easily present values in scientific notation, including uncertainty and/or units, as prescribed by Wikipedia's Manual of Style.

Introduction[redigér wikikode]

Val stands for the number value that is its first parameter. Val specializes in scientific notations and uncertainty notations, and in a measurement value with physical units. It formats the number (with possible unit) according to the Manual of Style and keeps the expression from wrapping across lines.

Express a numeral:

  • {{val|123456.78901}}value, formated with gaps: 123456.78901, or with |fmt=commas1.234,5678901.
  • {{val|number|number}}value ± uncertainty, like 123.478±56
  • {{val|number|(number)}}value(uncertainty), like 12.345(56).
  • {{val|number|number|number}}value +uncertainty−uncertainty like 1234+5678

Express a measurement value with a unit, for example {{val|4|ul=m/s2}}4 m/s2. The keyboard characters m/s2 are a "unit code" that |u=m/s2 marks up, or that |ul=m/s2 additionally links to its articulation.

Because the unit spacing and markup is a style issue, Val provides these for you. There are a large number of unit codes that Val understands and keeps "up to code". A unit code is usually composed of one or more abbreviated unit names and the usual math symbols on the typical keyboard. See {{Val/units}}.

Some unit-code flexibility is provided by having four parameters to work the unit-code system: whether to link one or not, (see Overlinking) , and whether to form a ratio or not with a unit code.

  • {{val|number|u=unit code}}number markup , such as 9.8 m/s2
  • {{val|number|ul=unit code}}number [[Article|markup]], such as 9.8 m/s2
  • {{val|number|u=unit code|upl=unit code}}number markup/[[Article|markup]], such as 9.8 m/s2
  • {{val|number|ul=unit code|up=unit code}} → [[Article|markup]]/markup, such as 9.8 m/s2

To bypass the unit code system, if |u= does not recognize your unit code, it will accept any wikitext and render it as usual.

  • {{val|5.4|u=[[kg]]&sdot;[[meter|m]]/s<sup>2</sup>}}5.4 kgm/s2
  • {{val|7.6|u=[[metre per second squared|m/s<sup>2</sup>]]}}7.6 m/s2

See below for § How to add units to the unit code system.

Sometimes a number and unit code is not enough. A prefix or suffix are also available, |p= and |s=.

  • {{val|7600|u=C&sdot;Ga|p=>|s=<}}>7600 C⋅Ga<
  • {{val|7600|u=C|p=<span style="color:green"><sup>|s=</span></sup>}}7600 C

See {{val/testcases}} to learn the val parameters by a example. It's comprehensive, and there's over 100 examples.

Arguments[redigér wikikode]

1st The numeric basis of the value. Defaults to 100.

{{val|1234567.1234567}}1234567.1234567
{{val|.1234}}0.1234                     (adds the zero)
{{val|+1234}}+1234                     (passes the plus)
{{val|-1234}}−1234                     (replaces dash with minus)
{{val|1234}}1234                     (four-digits pure)

2nd Uncertainty in either format.

{{val|11|22}}11±22
{{Val|11|(22)}}11(22)

3rd Asymmetric uncertainty.

{{Val|11|22|33}}11+2233

|e= Exponential.

{{Val|11|22|33|e=11}}11+2233×1011

|fmt= Format strings of digits. Accepts |fmt=commas for the integer part, but commas ignores the fractional part. Defaults to gaps, except for four digits. Four digits accept |fmt=gaps.

{{val|1234567.1234567|fmt=commas}}1.234.567,1234567.
{{val|1234|fmt=gaps}}1234.

|u= or |ul= The unit code. Val adds a space and the unit.

|ul= Link the unit.
|u= Don't link the unit. Also accepts wiki markup in lieu of a unit code.
{{val|11|ul=m}}11 m

|up= or |upl= A unit code, but Instead of a space Val adds a slash and the unit, a "per" unit (the denominator), to form a ratio.

|upl= Link the per unit.
|up= Don't link the per unit.
The ratio can be of two unit codes, or a prefix and a unit code. Val will add parentheses to disambiguate, if a unit code has a dot or a slash.
{{Val|11|ul=J/C|upl=F/m}}11 (J/C)/(F/m)
{{Val|11|upl=acre|p=$}}$11/acre
{{Val|11|ul=km/s|upl=Mpc}}11 (km/s)/Mpc
{{Val|11|ul=kg.m|upl=s-2}}11 (kg⋅m)/s−2

|p= Prefix. Non-spaced, but accepts markup.

{{Val|11|22|ul=m/s|p=<Prefix>}}<Prefix>11±22 m/s
{{Val|11|22|ul=m/s|p=<Prefix>&nbsp;}}<Prefix> 11±22 m/s

|s= Suffix. Non-spaced, but accepts markup.

{{Val|11|22|ul=m/s|s=<Suffix>}}11±22 m/s<Suffix>
{{Val|11|22|ul=m/s|s=&nbsp;<Suffix>}}11±22 m/s <Suffix>

|end= Add something between the base number and what follows. This is how Val can do numeric ranges.

{{val|30|end={{ndash}}50|ul=km}}30 – 50 km
{{val|30|end=&ndash;{{gaps|1|234|567}}|ul=km}}301234567 km
{{val|1234567|fmt=commas|end={{ndash}}1,234,567|ul=km}}1.234.567 – 1,234,567 km
{{val|11|ul=m/s|end=<END>}}11<END> m/s
{{val|11|22|ul=m/s|end=<END>}}11<END>±22 m/s
{{val|11|(22)|ul=m/s|end=<End>}}11<End>(22) m/s
{{val|11|22|33|ul=m/s|end=<End>}}11<End>+2233 m/s
{{val|11|ul=m/s|end=<End>}}11<End> m/s

|errend= or |+errend= and |-errend= Appends something after an uncertainty.

{{val|11|22|ul=m/s|errend=<Errend>}}11±22<Errend> m/s.
{{val|11|22|33|+errend=<Errend>|-errend=<Errend>}}11+22<Errend>33<Errend>.

|sortval= Alternative sorting factor to 1
|us= or |ups= Alternative unit code for sorting. {{val|12|u=kB|us=kiB}} will display 12 kB but sort as 12 kiB.
|long scale= Usually a unit is the short ton and billion means 1×109. But there are long versions of these units and others. Use |long scale=on to assign your unit to the long scale instead. The unit code's link will change and it will sort differently in tables. "See Long and short scales".
|nocategory= If set to any value, errors in the use of this template will not cause the page to be added to the Pages with incorrect formatting templates use category. This is useful for documentation and test pages that do not need to be fixed.

Errors[redigér wikikode]

There is strict checking on the validity of arguments; any incorrect use will result in an error, which is displayed using {{FormattingError}}. Pages that contain incorrect use of this template will show up on Category:Pages with incorrect formatting templates use.

Format of numbers[redigér wikikode]

{{Val}} produces formatting compliant with Wikipedia's Manual of Style.

The MOS recommends that numbers either be delimited using thin spaces either side of the decimal, or commas to the left and no delimiters to the right. Articles should be consistent with respect to the style of delimiting. The template defaults to the former style, this can be adjusted using |fmt= (see above).

Sorting[redigér wikikode]

A hidden sort key is added to the output for sorting in sortable tables. The sort key is based on the main value (parameter |1=) and, if used, the exponent for the power of 10 (parameter |e=) and/or units (parameters |u=, |ul=, |up= and/or |upl=). Where necessary, units are converted to base SI units for the purpose of the sort key, which is produced by {{ntsh}}. Several units are covered; see ¶ How to add units for those which are not. To omit the sort key use |sortable=off.

Examples[redigér wikikode]

Number

{{val|1234567.1234567}}1234567.1234567
{{val|.1234567}}0.1234567
{{val|+1234567}}+1234567
{{val|-1234567}}1234567

Uncertainty

{{val|1.234|0.005}}1.234±0.005
{{val|1.234|+0.005|-0.006}}1.234+0.0050.006
{{val|1.234|(5)}}1.234(5)

Units

{{val|1.234|u=m}}1.234 m
{{val|1.234|u=m2}}1.234 m2
{{val|1.234|ul=m}}1.234 m
{{val|123.4|ul=USgal}}123.4 US gal
{{val|12.34|ul=mpgimp}}12.34 mpgimp

{{val|12.34|u=deg}}12.34° 
{{val|1.234|0.005|u='}}1.234±0.005′ 
{{val|1.234|+0.005|-0.006|u="}}1.234+0.0050.006 

Exponents

{{val|1.234|e=5|ul=m}}1.234×105 m
{{val|1.234|0.056|e=7}}(1.234±0.056)×107
{{val|1.23456|+0.00007|-0.00008|e=-9|ul=m/s}}1.23456+0.000070.00008×109 m/s
{{val|1.234|0.056|e=7|ul=psi}}(1.234±0.056)×107 psi
{{val|1.234|(5)|e=-2}}1.234(5)×102

Prefix/suffix

{{val|12.34|p=Δ&nbsp;}}Δ 12.34
{{val|12.34|u=%|p=≅}}12.34
{{val|12.34|0.25|s=%}}12.34±0.25%

Numerator/Denominator

{{val|1.234|e=7|ul=W|up=m2}}1.234×107 W/m2

Even more examples

See the testcases at {{val/testcases}}.

Performance impact[redigér wikikode]

For very long list articles with hundreds of numeric entries, load times for that page will be much much faster by using html. No templates can compete with HTML on, for example List of nuclides.

Performance data is reported by MediaWiki software in the HTML page source of every page, and a very similar report is available on any preview page, below the edit box, titles "Parser profile data". For using Val inside other templates, note the performance parameter in these reports, called "Highest expansion depth". Numbers with fractional parts cost more Val-expansion depth than numbers with only integer parts.

For uses in any other page besides long list articles, Template:Val will have no noticeable impact on CPU time contributions to page-load times.

How to add units[redigér wikikode]

Add the unit to Template:Val/units. Val defaults to looking up units at {{Convert}}, but units added here override that.

Note these points about composite units before adding units:

  • For composite units you should probably link the whole, not individual units. For example the line you add would say |m.s-1=[[Metre per second|m&sdot;s{{sup|−1}}]] linking to Metre per second, not |m.s-1=[[Metre|m]]&sdot;[[Second|s]]{{sup|−1}}.
List of common physics notations has many examples of composite units that have their own page.
  • The val user can compose their own divisor unit from an existing unit, for example writing {{val|99|ul=m|upl=s}} to render their own "99 m/s" with two links: m to Meter and s to Second.
  • The val user can compose their own multiplier units by using the end parameter to prepend a string. For example, in a geology article, to prepend "Ma", to the unit in 333 14C yr BP, use {{val|333|ul=uBP|end=&nbsp;[[megaannum|Ma]]}}333 Ma 14C yr BP". (The end parameter accepts wikitext, so it can be linked.)

After adding a unit, you can ensure that it sorts correctly in a table, especially if there are ten or twenty variations that differ only by an SI prefix. (See ¶ Sorting above and Template:Val/sortkey/unit.)

FAQ and comments[redigér wikikode]

  • Q: Why should I use Val?
A1: Val formats numbers:
A2: Val preserves spacing:
  • It makes sure the value does not wrap at the end of a line, so that it can always be read as a single value on one line in the text.
  • It spaces the various parts of the value where they should be
A3: Configuring Val gives you your own code for automating the markup for, and a link to, any units in the entire Encyclopedia.
A4: Val helps make Wikipedia more consistent. It adheres to the Wikipedia Manual of Style for numbers. Updates to the MoS can be applied to this template, and result in automatic modification on values that use it. All this makes sure all values on all pages have the same look and feel because they will all use the same spacing, font size, positioning, etc, and makes updating and checking by the bots easier because they can recognize a value for what it is.
  • Q: Why not use <math>?
A: For the same reasons HTML might be preferred over TeX:
  • Because the font in math tags differs both in face and size from the prose, which can disturb the layout of a page when used inline with the prose.
  • You cannot cut and paste a bitmap image rendered by the Latex.
  • Images are slower to load and use more bandwidth, which is especially bad for the mobile version of Wikipedia.
  • <math> does not automatically easily align to the Manual of Style for numbers.
  • Q: Are there any known issues with Val?
A1: This template has been in full use on many pages for quite some time without major problems or breaking changes. Technically, there is no good reason not to try Val.
A2: Issues are solved rapidly by an active set of responsive template coders. See the talk page.
  • Q: How should I use Val?
A1: Val probably already has your unit on its current list. If not, then your unit can be added.
A2: To avoid over linking switch from |ul= to |u= and from |upl= to |up=.
A3: Use Val along with {{Convert}}. See how to add units to Convert.

Se også[redigér wikikode]

  • {{Val}} subtemplates:
    {{Val/units}}, for the list of customized units, their markup, their link, and to configure your own codename for your own unit (whose name you choose goes into any of the named parameters with the letter u in there names).
    Similarly {{Val/angle}}, for the handling of unspaced units.
    {{val/delimitnum}}, for setting your own delimiters between groups of digits instead of using the default (spaces).
    {{Val/sortkey/unit}} for guaranteeing table sorting
  • {{formatting error}}, to fix inconsistencies when the error you are given is not the error you find you have.
Dette er TemplateData-dokumentationen til denne skabelon, brugt af VisualEditor og andre værktøjer.

Val

Ingen beskrivelse.

Skabelonparametre

Denne skabelon foretrækker inline-formatering af parametre.

ParameterBeskrivelseTypeStatus
Værdi1

ingen beskrivelse

Talpåkrævet
Usikkerhed (positiv del hvis asymmetrisk)2

ingen beskrivelse

Eksempel
22 → Værdi±22; (22) → Værdi(22)
Strengvalgfri
Asymmetrisk usikkerhed (negativ del)3

ingen beskrivelse

Talvalgfri
Enhed eller første del af enhed (uden wikilink)u

ingen beskrivelse

Indholdvalgfri
Enhed eller første del af enhed (med wikilink)ul

ingen beskrivelse

Ukendtvalgfri
Nocategorynocategory

ingen beskrivelse

Ukendtvalgfri
up – Anden del af enhed til visning efter en skråstreg (uden wikilink)up

ingen beskrivelse

Strengvalgfri
upl – Anden del af enhed til visning efter en skråstreg (med wikilink)upl

ingen beskrivelse

Strengvalgfri
Sortablesortable

ingen beskrivelse

Ukendtvalgfri
Sortvalsortval

ingen beskrivelse

Ukendtvalgfri
Ee

ingen beskrivelse

Ukendtvalgfri
Usus

ingen beskrivelse

Ukendtvalgfri
Upsups

ingen beskrivelse

Ukendtvalgfri
Long scalelong scale

ingen beskrivelse

Ukendtvalgfri
Pp

ingen beskrivelse

Ukendtvalgfri
Fmtfmt

ingen beskrivelse

Ukendtvalgfri
Endend

ingen beskrivelse

Ukendtvalgfri
Ww

ingen beskrivelse

Ukendtvalgfri
Aa

ingen beskrivelse

Ukendtvalgfri
+errend+errend

ingen beskrivelse

Ukendtvalgfri
-errend-errend

ingen beskrivelse

Ukendtvalgfri
Errenderrend

ingen beskrivelse

Ukendtvalgfri
Ss

ingen beskrivelse

Ukendtvalgfri