Plantilla:Val/ús

De la Viquipèdia, l'enciclopèdia lliure

Introducció[modifica]

Val s'especialitza en valors numèrics, especialment aquells amb notacions científiques, d'incertesa, i en valors de mesura amb unitats físiques. Com que aquestes expressions estan cobertes pel Manual d'estil, Val us proporciona la sortida estilitzada i evita que s'ajusti (parteixi el valor, si conté, per exemple, el número i les unitats de mesura) entre línies.

Expressió d'una mesura:

  • {{val|123456.78901}}valor, formatat amb punts: 123.456,78901, o amb espais |fmt=gaps123456,78901
  • {{val|número|número}}valor ± incertesa, com ara 123.478±56
  • {{val|número|(número)}}valor(incertesa), com ara 12.345(56)
  • {{val|número|número|número}}valor +incertesa
    −incertesa
    com ara 1.234+56
    −78

Expressió d'una mesura amb unitats: {{val|4|ul=m2}}m2. El m2 és un "codi d'unitat" que Val utilitza per buscar l'enllaç a l'article de la unitat i el format del símbol de la unitat. Vegeu {{Val/list}}.

Hi ha un gran nombre de codis d'unitats que Val entén i manté “al dia”. Un codi d'unitat és el nom de la unitat abreujat, però pot participar en una unitat composta o composta, amb "multiplicadors" o "divisors". Vegeu Mòdul:Val/units.

Hi ha una mica de flexibilitat del codi d'unitat, proporcionant quatre paràmetres per treballar-hi: si disposa d'un enllaç o no (vegeu Sobreenllaç) i si s'enllaça el numerador o el denominador d'una relació d'unitats per separat.

  • {{val|número|ul=codi d'unitat}}númerosymbol, com ara 9,8 km2
  • {{val|número|u=codi d'unitat}}number symbol, com ara 9,8 km2
  • {{val|número|u=codi d'unitat|upl=codi d'unitat}}número symbol/symbol, com ara 9,8 gal/min
  • {{val|número|ul=unit code|up=codi d'unitat}}número symbol/symbol, com ara 9,8 pc/any

Per evitar el sistema de codis de la unitat, amb |u= no reconeix el codi de la vostra unitat, acceptarà qualsevol wikitext i es mostrarà com de costum.

  • {{val|5.4|u=[[kg]]&sdot;[[metre|m]]/s<sup>2</sup>}}5,4 kgm/s2
  • {{val|7.6|u=[[metre per segon al quadrat|m/s<sup>2</sup>]]}}7,6 m/s2

Vegeu Mòdul:Val/units per afegir unitats al sistema de codis d'unitat.

De vegades, un número i un codi d'unitat no són suficients. També hi ha disponibles un prefix o un sufix, |p= i |s=.

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

Vegeu {{val/testcases}} per obtenir informació sobre els paràmetres val mitjançant un exemple. És exhaustiu i hi ha més de 100 exemples.

Arguments[modifica]

Val pren tres paràmetres sense nom. El primer sempre és el valor numèric. Quan el segon i el tercer són números, es converteixen en diverses notacions d'incertesa, però el segon paràmetre sense nom també pot servir per "unir gramaticalment" el primer i el tercer número.

Val neteja els espais circumdants en els seus paràmetres sense nom.

1r or |1= Un número. Pot estar en una notació amb punt decimal o amb notació e. Aquest número és la base del format Val.

{{val|1234567.1234567}}1.234.567,1234567
{{val|.1234}}0,1234                    (afegeix el zero )
{{val|+1234}}+1.234                     (mostra el més)
{{val|-1234}}−1.234                     (substitueix el guionet pel signe meys)
{{val|12e34}}12×1034                (notació e)

|fmt= Per defecte, els números es formaten amb punts que separen grups de tres dígits tant en la part sencera com en la part fraccionària.

Utilitzeu |fmt=gaps per delimitar la part sencera del nombre amb espais.
Utilitzeu |fmt=none sense format (sense espais ni punts).
{{val|1234567.1234567}}1.234.567,1234567
{{val|1234567.1234567|fmt=commas}}1.234.567,1234567
(presentació per defecte, obsoleta) {{val|1234}}1.234
{{val|1234|fmt=gaps}}1234
{{val|1234.5}}1.234,5
{{val|1234.5|fmt=none}}1234.5

|end= Posa alguna cosa al final del número principal (abans de qualsevol altra cosa que pugui seguir).

{{val|11|end=<END>}}11<END>
{{val|11|22|end=<END>}}11<END>±22
{{val|1111|(22)|end=<END>}}1.111<END>(22)
{{val|11|22|33|end=<END>}}11<END>+22
−33

{{val|11|ul=m/s|end=<END>}}11<END> m/s

2n o |2= Incertesa en altre format.

{{val|11|22}}11±22
{{Val|11|(22)}}11(22)
Una conjunció per unir dos números. Útil per a intervals, sortida gramatical, etc.
{{val|11|-|33}}11–33
{{val|11|–|33}}11–33
{{val|11|,|33}}11, 33
{{val|11|by|33|e=9}}(11 per 33)×109
{{val|11|and|33|end=$}}11$ i 33$
{{val|11|or|33}}11 o 33
{{val|11|to|33}}11 a 33
{{val|11|x|33}}11 × 33
{{val|11|×|33}}11 × 33
{{val|11|/|33|ul=m/s}}11/33 m/s
Note that for dashes or x's, the various kinds all obtain one properly styled output.

3r o |3= Incertesa asimètrica.

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

|errend= o |+errend= i |-errend= Afegeix alguna cosa després d'una incertesa.

{{val|11|22|errend=<Errend>}}11±22<Errend>
{{val|11|22|33|+errend=<+Errend>|-errend=<−Errend>}}11+22<+Errend>
−33<−Errend>

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

|ul= Enllaça a la unitat.
|u= No enllaça a la unitat. Also accepts wiki markup in lieu of a unit code.
{{val|11|ul=m}}11 m

|up= o |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= Enllaça a la unitat.
|up= No enllaça a la unitat.
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)
{{#invoke:DemoTemplate|Val|11|p=$|upl=[[Acre (unitat de superfície)|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 the entire Val expression. 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 the entire Val expression. 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>

|e= Exponent. Val alternatively accepts e notation in the first parameter; these are mutually exclusive (see "1st" argument above).

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

{{Val|11e11|22|33}}11+22
−33
×1011

{{Val|e=33}}1033

|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 categoria Pàgines amb ús de plantilles de format incorrecte. This is useful for documentation and test pages that do not need to be fixed.

Errors[modifica]

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 Categoria:Pàgines amb ús de plantilles de format incorrecte.

Val comprova si hi ha paràmetres no admesos i dóna un avís relativament clar si es troba. Manteniu el ratolí sobre "avís" per veure els detalls. A continuació, es mostren els advertiments:

  • {{val|1.23|exp=6|u=m/s}}1,23 m/sError a {{val}}: El paràmetre "exp=6" de val no s'admet
  • {{val|1.23|us=kbit/s}}1,23Error a {{val}}: El paràmetre "us=kbit/s" de val no s'admet
  • {{val|1.23|.05|.04|.03|u=m/s}}1,23+0,05
    −0,04
     m/s
    Error a {{val}}: S'ha ignorat el paràmetre 4 de val

Format convention[modifica]

As mentioned before, {{val}} should produce formatting compliant with Wikipedia's Manual of Style. It currently produces formatting compliant with the U.S. Government Printing Office Style Manual, in rules 12.9e and 12.14, which requires that the decimal separator be a full stop; i.e. “decimal point” (.), requires comma-delimiting to the left of the decimal point for numbers with four or more digits to the left (values of 1.000 or more), and also requires space-delimiting to the right of the decimal point for numbers containing five or more digits to the right (e.g., 0,12345 and 5,12345 and 125,12345).

Note that if {{val}} is used on numbers simultaneously comprising four or more digits to the left of the decimal point and five or more digits to the right, the resultant expression will delimited with commas left and spaces (actually non-selectable, non-breaking, narrow gaps) right (see below).

Ordenació[modifica]

La clau d'ordenació de cada unitat ordenable és visible a {{Val/list}}.

Aquí teniu un exemple en directe que mostra el marcador mínim per a una taula ordenable:

{| class="sortable"
! Prova d'ordenació de val
! En la unitat base
|-
| {{val|3|ul=  Mm }}
| {{val|3000000|u=m}}
|-
| {{val|4e6|ul= m }}
| {{val|4000000|u=m}}
|-
| {{val|1|ul=  km }}
| {{val|1000|u=m}}
|-
| {{val|5e3|u=  m }}
| {{val|5000|u=m}}
|-
| {{val|2|u=    m }}
| {{val|2|u=m}}
|}
Clica per ordenar ↓
Prova d'ordenació de val En la unitat base (no ordenat)
Mm 3.000.000 m 91
4×106 m 4.000.000 m 25
km 1.000 m 59
5×103 m 5.000 m 93
2 m 2 m 61

Un valor d'ordenació es relaciona amb una expressió Val de la següent manera.

  1. El valor numèric és un punt de partida.
  2. Si la unitat té un prefix SI, s'aplicarà aquest ordre de magnitud.
  3. S'aplica el valor de la unitat del seu propi sistema d'unitats.
  4. Si la unitat és composta, cada subunitat es multiplica o divideix per la seva dimensió.
  5. El resultat es passa a {{ntsh}} que aplica una fórmula de normalització.
  6. La sortida de {{ntsh}} s'afegeix (només de manera conductual, és a dir, "oculta") a la taula com de costum, mitjançant l'atribut data-sort-value d'una taula.

Exemples[modifica]

{{val|1234567.1234567}}1.234.567,1234567
⟨{{val|  1234567.1234567   }}⟩ → ⟨1.234.567,1234567
{{val|.1234567|fmt=commas}}0,1234567
{{val|+1234567|fmt=commas}}+1.234.567
{{val|-1234567}}−1.234.567

Incertesa[modifica]

{{val|1.234|0.005}}1,234±0,005
{{val|1.234|0.005|e=3}}(1,234±0,005)×103
{{val|1.234|+0.005|-0.006}}1,234+0,005
−0,006

{{val|1.234|(5)}}1,234(5)

Unitats[modifica]

{{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 mpg-imp

{{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,005″
−0,006″

{{val|1.234|u=%}}1,234%
{{val|1.234|end=&nbsp;[[m/s]]}}1,234 m/s

{{val|12.34|u=degC}}12,34 °C
{{val|12.34|u=K}}12,34 K

Exponents[modifica]

{{val|e=5}}105
{{val|e=5|ul=m}}105 m

{{val|1.234e5|ul=m}}1,234×105 m
{{val|1.234|e=5|ul=m}}1,234×105 m

{{val|1.234e7|0.056}}(1,234±0,056)×107
{{val|1.234|0.056|e=7}}(1,234±0,056)×107

{{val|1.23456e-9|+0.00007|-0.00008|ul=m/s}}1,23456+0,00007
−0,00008
×10−9 m/s

{{val|1.23456|+0.00007|-0.00008|e=-9|ul=m/s}}1,23456+0,00007
−0,00008
×10−9 m/s

{{val|1.234e7|0.056|ul=psi}}(1,234±0,056)×107 psi
{{val|1.234|0.056|e=7|ul=psi}}(1,234±0,056)×107 psi

{{val|1.234e-2|(5)}}1,234(5)×10−2
{{val|1.234|(5)|e=-2}}1,234(5)×10−2

Prefix/sufix[modifica]

{{val|12.34|p=Δ&nbsp;}}Δ 12,34
{{val|12.34|u=%|p=≅}}≅12,34%
{{val|12.34|0.25|s=%}}12,34±0,25%

Numerador/denominador[modifica]

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

More examples
See the testcases at Val/test.

Performance impact[modifica]

For most uses, in the text of articles, Template:Val will not restrict performance, but when used inside the wikitext markup of large templates, there are some restrictions. When displaying integer amounts, Template:Val has an internal expansion depth of 15 levels, but for numbers with decimal portions, it uses 22 levels, or more.

How to add units[modifica]

The unit you will add is required to have a link version and a non-link version for stylistic reasons (including the ability of editors to avoid overlinking). The link version will be added to Val/unitswithlink to process the ul and upl parameters. The non-link version might need to be added to Val/units to process the u and up parameter; it depends on whether or not the unit needs markup, or if the characters users will give to the ul or u parameter are different than what is displayed, or if "technical reasons" are discovered. (See below.)

Note these points 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=[[Velocity|m·s{{sup|−1}}]] linking to Velocity, not |m*s-1=[[Metre|m]]·[[Second|s]]{{sup|−1}}. List of common physics notations has many examples of composite units that have there own page.
  • The val user can compose their own divisor unit from an existing unit, writing {{val|ul=m|upl=s}} to render there own "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, to prepend "Ma", they could write {{val|333|end=&nbsp;Ma|ul=uBP}}, rendering "333 Ma 14C yr BP". These cannot be linked.

The technique involves activating "Show changes" to catch unintended changes that are otherwise difficult to detect in any of the many pages using val that would be affected.

  1. Edit {{Val/unitswithlink/test}}. The LHS of the "=" sign is what val users will give to the ul (or upl) parameter. Activate "Show preview". This will run your test data through val, which would be similar to running val itself in a sandbox. Prove the intended link and markup here because you will not be able to show a preview in the next steps. Copy what you will be adding to the wiki with the next steps. Save the page to serve as a "current list".
  2. Edit {{Val/unitswithlink}}. Paste the identical line proven in step 1. Sort order is not important. Show changes, and then save.
  3. If the unit will display differently from what is typed into u=, edit {{Val/units}}. Paste the identical line, and remove any links from the RHS of the "=" sign, being careful to leave any rendering work. Show changes, and then save.
  4. Important. Run {{Val|u=}} and {{Val|ul=}} in a sandbox and verify that your unit has an identical appearance in both cases. Edit {{Val/units}} to make any corrections. (The discrepancy occured for technical reasons.)

The last step is an important to the manual of style for dates and numbers.

FAQ and comments[modifica]

  • Q: Why should I use val?
A1: {{Val}} formats numbers:
A2: It 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: It automates the markup for, and a link to a displayed unit.
A4: Val helps make Wikipedia more consistent. It adheres to the Wikipedia Manual of Style for numbers. Updates to the Wikipedia Manual of Style for numbers can be applied to this template, and result in automatic modification on values that use val. 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 [[Help:Math#Pros_of_HTML|HTML might be preferred over Plantilla: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 adhere to the Wikipedia Manual of Style for numbers.
  • Q: Are there any known issues with val?
A1: Because numbers can only be stored with a limited precision by Wikipedia servers, val cannot handle very large numbers, such as 123456789123456789. This is reported using a {{FormattingError}}, so it should be easy to spot. Since there is very limited use for such large numbers, there is no fix planned for this.
A2: 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.
  • 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 the ul= to the u= parameter of the given unit.

See also[modifica]

  • {{Valid}} : number validity checking (for parameters 1, 2, 3, e : value, and uncertainties, base-10 exponent)
  • {{FormattingError}} : for reporting inconsistent parameters
  • {{Val/delimitnum}} : for formatting a decimal number with delimiters between groups of digits
  • {{Su}} : for formatting exponents, or two-values incertainty one below the other (monospaced : currently not printable to PDF)
  • {{±}} : for positive <sup> and negative <sub>
  • {{Val/units}} : for formatting unit names (contents of parameters u or up)
  • {{Val/unitswithlink}} : for formatting unit names with links (contents of parameters ul or upl)

TemplateData[modifica]

Aquesta és la documentació dels paràmetres de la plantilla utilitzada pel nou editor visual.

Val

Aquesta plantilla s'utilitza per presentar fàcilment valors en la notació científica, incloses la incertesa i/o les unitats, tal com s'explica al Manual d'estil de la Viquipèdia.

Paràmetres de la plantilla

Aquesta plantilla prefereix el format de paràmetres en la mateixa línia.

ParàmetreDescripcióTipusEstat
Número1

Un número en notació de punt decimal o en notació e. La base principal de l'expressió Val.

Exemple
-12.12345e9
Cadenaobligatori
Incertesa2

cap descripció

Cadenaopcional
Incertesa asimètrica -3

cap descripció

Cadenaopcional
Formatfmt

Per defecte, els números es formaten amb punts que separen grups de tres dígits tant en la part sencera com en la part fraccionada. Utilitzeu "gaps" (sense cometes) per forçar espais. Utilitzeu "none" sense cometes) per no formatar (sense punts).

Exemple
gaps
Cadenaopcional
Finalend

Posa alguna cosa al final del número principal (abans que qualsevol altra cosa que pugui seguir).

Cadenaopcional
Unitatu

El codi de la unitat. Un espai i la unitat s'afegiran després del número.

Exemple
m
Cadenaopcional
Unitat - enllaç al wikiul

El codi de la unitat que s'enllaçarà a una pàgina amb informació sobre la unitat. Un espai i aquesta unitat s'afegiran després del número.

Exemple
m
Cadenaopcional
Unitat que s'ha de posar amb una barra inclinada (/)up

Un codi d'unitat, però en lloc d'un espai, la plantilla afegeix una barra inclinada i la unitat, una unitat "per" (el denominador), per formar una fracció.

Exemple
s
Cadenaopcional
La unitat s'ha de posar amb una barra inclinada (/) – enllaç al wikiupl

Un codi d'unitat enllaçat al wiki, però en lloc d'un espai, la plantilla afegeix una barra inclinada i la unitat, una unitat "per" (el denominador), per formar una fracció.

Exemple
s
Cadenaopcional
Prefixp

Prefix per a tota l'expressió de Val. No espaiat, però accepta marques.

Contingutopcional
Sufixs

Sufix per a tota l'expressió Val. No espaiat, però accepta marques.

Contingutopcional
Exponente

Val també accepta la notació e en el primer paràmetre; són excloents mútuament (vegeu el paràmetre Número).

Exemple
9
Nombreopcional
errenderrend

cap descripció

Desconegutopcional
44

cap descripció

Desconegutopcional
55

cap descripció

Desconegutopcional